semi-newbie module namespace confusion

Magnus Lycka lycka at carmen.se
Fri Oct 7 04:01:00 EDT 2005


pnau at sjm.com wrote:
> The main jist of the problem is that I'm trying add data from one
> module to a list and a dictionary in another module, and it doesn't
> seem to stick over there.

It's probably best to avoid any circular depentencies, but as
long as you make sure you really use your modules as modules,
and not one of them aas a main prorgam, I think it should work.

$ cat > a.py
import b
def set_b(n):
     b.b=n
$ cat > b.py
import a
def set_a(n):
     a.a=n
$ python
Python 2.2.3 (#1, Feb  2 2005, 12:20:51)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import a,b
 >>> a.set_b('B')
 >>> b.set_a('A')
 >>> a.a
'A'
 >>> b.b
'B'
 >>>



More information about the Python-list mailing list