Circular Class Logic

half.italian at half.italian at
Thu Mar 15 01:35:48 CET 2007

I have a set of classes that describe Files, Folders, etc., that I use
often in my scripts for moving files around, getting a files
extension, converting paths, changing permissions, etc  It's very
similar to Jason Orendorff's 'Path' library, and is very useful to
me.  The base class '' stores all the basic attributes of any
piece of data on disk, and it is then subclassed to represent files
and folders with the attributes specific to that type of object.

I recently made a new class '' that is a subclass of
'', to describe all of the attributes of any local or network
disks attached to the computer.  I subclassed it from Folder, because
it really is a folder, it's just at the root of a drive.  I'm
realizing that these 'Disk' objects are pretty useful, and I came up
with the idea to put a 'Disks' instance as a shared class variable
(singleton?) within the base class ('Data')  The idea being that any
instance of a File, or Folder object would contain the list of Disk
objects attached to the system, and could use them accordingly.  Also
important is that I would only need to gather the disk info once for
any given running application and all the instances could use it
(origianlly I was getting the disk info for each File/Folder object)

After an hour of banging my head from getting "AttributeError:
'module' object has no attribute 'Disks'" errors, I finally realized
that I'm trying to include an instance in the base class that is a
subclass of itself.  Short of making 'Disk' no longer a subclass of
Folder, is there any other way to include a subclassed instance in the
base class of that object? (this is very hard to put in to words)


More information about the Python-list mailing list