Circular Class Logic

half.italian at gmail.com half.italian at gmail.com
Thu Mar 15 22:02:29 EDT 2007


> > How is that really different from this:
>
> > class Disk(Folder):
> >   def __init__(self,driveLetter):
> >     Folder.Folder.__init__(self.path) # ???  Being that Folder is the
> > superclass?
>
> Where did self.path come from?  Even though Folder is the superclass,
> self.path doesn't exist until the Folder.__init__ method gets called.
> This ain't C++ you know.

My bad. I should have said:

class Disk(Folder):
  def __init__(self,driveLetter):
    Folder.Folder.__init__(self, driveLetter + ":/")

> Knock yourself out.  I just hacked together these Folder/Disk classes
> by way of a half-baked-but-working example.  My point is that to
> initialize a class level variable on class Foo, all that is needed is
> to assign it in the defining module, that is:
>
> class Foo:
>    pass
>
> Foo.fooClassVar = "a class level variable"

> Now any Foo or sub-Foo can access fooClassVar.  The type of
> fooClassVar can be anything you want, whether it is a Foo, subclass of
> Foo or whatever, as long as it has been defined by the time you assign
> fooClassVar.

That was the first thing I tried, but because the libs were importing
each other, etc, it got hung up with wierd "This module doesn't exist"
errors, when it clearly did.

~Sean






More information about the Python-list mailing list