Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18748

Re: Calling a variable inside a function of another class

Date 2012-01-10 12:03 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: Calling a variable inside a function of another class
References <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4587.1326193399.27778.python-list@python.org> (permalink)

Show all headers | View raw


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 http://www.python.org/dev/peps/pep-0008/ )
- 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.

JM

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Calling a variable inside a function of another class Yigit Turgut <y.turgut@gmail.com> - 2012-01-07 07:00 -0800
  Re: Calling a variable inside a function of another class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-07 16:01 +0000
    Re: Calling a variable inside a function of another class Yigit Turgut <y.turgut@gmail.com> - 2012-01-07 08:18 -0800
      Re: Calling a variable inside a function of another class Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-01-07 14:03 -0500
  Re: Calling a variable inside a function of another class Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-01-10 12:03 +0100
  Re: Calling a variable inside a function of another class Terry Reedy <tjreedy@udel.edu> - 2012-01-10 17:41 -0500

csiph-web