newbie class troubles

Remco Gerlich scarblac-spamtrap at
Sun Sep 17 19:17:54 CEST 2000

Brett Lempereur wrote in comp.lang.python:
> erm... no. my code at the minute is:
> 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)
> that's the class.  you already know the error

You can't call methods on a class, you can only call them on instances
(that's where the "self" is filled in, as it were). Make an instance
of the class, then pass its method.

Since you do nothing with self inside the function, I don't think it
should be part of a class at all. Same for the variables. But maybe
there's other code that makes the variables useful...

Remco Gerlich,  scarblac at
  Murphy's Rules, "Sinus Trouble":
   In FGU's adventure The King over the Water, a character must make a
   Sense Acuity roll to detect a pile of sixteen dead rats.

More information about the Python-list mailing list