sending a class as an argument
manstey
manstey at csu.edu.au
Sun Jan 28 23:24:23 EST 2007
Hi,
Our class has its attributes set as classes, as in
MyClass.Phone.Value='34562346'
MyClass.Phone.Private=True
Inside the MyClass definition we have a function like this:
def MyFunc(self,clsProperty):
if clsProperty.Private:
print 'Private property'
else:
print ClsProperty.Value
In our code, we then call
>>> MyClass.MyFunc(MyClass.Phone)
We want to be able in our code instead simply to call:
>>> MyClass.MyFunc(Phone) or MyClass.MyFunc('Phone')
But we can't get it to work. If we rewrite the function as follows:
def MyFunc(self,attr):
if self.attr.Private:
print 'Private'
else:
print self.attr.Value
we get an error.
Is there a better way to do this? Thanks
More information about the Python-list
mailing list