How two modules call functions defined in each other?
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Sun Mar 20 11:20:16 CET 2005
On 19 Mar 2005 18:07:31 -0800, rumours say that "Tian" <wangtianthu at gmail.com>
might have written:
>I am python beginner, I have a question about the interdependence of
>For example, when I have two modules:
> return add(x,1)
> return x+y
> return plus(x)+1
>How should I write "import" in both files?
In module1, import module2 and vice versa. From moduleX, you access any
attribute (function or "variable") of moduleY by using moduleY.attribute .
>What about the global varibals? is there anything like "extern" keyword
There are no "global variables" in Python, only module-level attributes. If by
global you mean the main program's (which is also a module) attributes, in your
other modules do a:
and then access its attributes as __main__.attribute . It's not generally a
good idea in Python, though, so you might like to explain what you need to do so
that we suggest alternate approaches.
>or python has some other solutions?
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
More information about the Python-list