Calling a variable inside a function of another class

Jean-Michel Pichavant jeanmichel at
Tue Jan 10 06:03:12 EST 2012

Yigit Turgut wrote:
> class test(test1):
>     def __init__(self, device):
>       .
>       .
>       .
>     def _something(self, x=1)
>      self.dt = data
> if __name__ == "__main__":
>      test.something.dt ???
> I am trying to call a variable located in a function of a class from
> main but couldn't succeed.Any ideas?

if __name__ == "__main__":
  aTest = test(whateverdevice)
  print aTest.dt

Some advices:

- a common practice in python is to name classes in CamelCase ( read )
- if dt is a shortcut for data, it's a bad one.
- default values are for loosers, they should be used only to keep backward compatibility (personal opinion, a lot of ppl would disagree)
- "call" is usually reserved for method and function, or any callable object in python. What you're trying to do is to reference an object, not calling it.


More information about the Python-list mailing list