Hello everyone,
Is it possible to define "static properties" in a class?
Example:
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 CurrentDirector y():
return os.getcwd()
CurrentDirector y = staticmethod(Cu rrentDirectory)
pwd = Path.CurrentDir ectory()
Question: Can I make CurrentDirector y a property? Just adding
CurrentDirector y = property(Curren tDirectory) after the staticmethod
line didn't work, unsurprisingly. :-)
Regards,
Per Erik Stendahl
Is it possible to define "static properties" in a class?
Example:
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 CurrentDirector y():
return os.getcwd()
CurrentDirector y = staticmethod(Cu rrentDirectory)
pwd = Path.CurrentDir ectory()
Question: Can I make CurrentDirector y a property? Just adding
CurrentDirector y = property(Curren tDirectory) after the staticmethod
line didn't work, unsurprisingly. :-)
Regards,
Per Erik Stendahl
Comment