Static properties

Per Erik Stendahl python-spam at
Thu Aug 26 16:34:05 CEST 2004

Hello everyone,

Is it possible to define "static properties" in a class?

I have a class, Path, that wraps a lot of os.* and os.path.* functions 
(and others), so I can write things like this:

x = Path('/usr/local/some/file')
if x.IsFile:
     contents = x.Read()

Now, I would like to wrap os.getcwd(). I can do it like this:

class Path:
     def CurrentDirectory():
         return os.getcwd()
     CurrentDirectory = staticmethod(CurrentDirectory)

pwd = Path.CurrentDirectory()

Question: Can I make CurrentDirectory a property? Just adding
CurrentDirectory = property(CurrentDirectory) after the staticmethod 
line didn't work, unsurprisingly. :-)

Per Erik Stendahl

More information about the Python-list mailing list