Reputation: 548
I have a scenario where I have following definitions in class. Don't worry about indentation please:
class A(objectRef //imported from another file):
def doSomething(self, object):
self.var1 = object.get("something");
Then I have another file with functions, but my reference is outside function in fileB. FileB.py contains
1) ref = A().doSomething.var1
2) ref = A().doSomething(self.var1)
3) val = A().doSomething().val1
These did not work.
Unfortunately its not a function its variable reference which are used in for loops later. The variable is then Then, I need to extract var1 from another file where no function exist. Importing part is easy for class but then how do I reference to get var1 from another file.
doSomething()
has hundreds of attributes referenced so unfortunately I won't be able to modify anything inside that. I would need to make things work from fileB.py as that is the one that needs to call class A()
Upvotes: 1
Views: 1667
Reputation: 5992
Or if you want to do it in the form A().doSomething().var1
, you can add
return self
to your A.doSometing
method.
Upvotes: 2
Reputation: 16126
If you want var1 then just do
obj = A()
obj.doSomething()
val = obj.var1
Upvotes: 4