newbie class troubles

Alex cut_me_out at hotmail.com
Sun Sep 17 14:15:01 EDT 2000


Brett
> class filesearch:
>     # Any public variables i need
>     exceptions = []
>     filelist = []
>     dirlist = []
> 
>     def search(self, top):
> 	  try:
> 	      tmpList = os.listdir(top)
> 	  except os.error:
> 	      return
> 
> 	  for item in tmpList:
> 	      if item not in exceptions:
> 		  name = os.path.join(top, name)
> 		  if os.path.isdir(name):
> 		      self.dirlist.append(name)
> 		      search(self, name)
> 		  else:
> 		      self.filelist.append(name)
> 

You're being pretty unclear, but I would guess that you were trying to
use this class in some fashion as

os.path.walk(dir, filesearch.search, 'dummy_arg')

If that's the case, the error is coming from the fact that
filesearch.search is an unbound method.   To correct it, you need to do
something like this, instead:

filesearch_instance = filesearch()
os.path.walk(dir, filesearch_instance.search, 'dummy_arg')

You will probably also need to amend the argument signature of the
search method.  It will probably need to take three arguments, not one.

Alex.

-- 
Speak softly but carry a big carrot.



More information about the Python-list mailing list