Package name with '.' in them: Python Bug ?

Yannick Patois patois at calvix.org
Fri Mar 19 15:49:49 CET 2004


Hi,

Under some naming conditions of module files, it seems that python lost 
class static variables values.
It seems only to append when importing a "badly" named module that 
itself import a module with a static variable in it (looks complex, but 
see the example below, pretty simple):

First a working example:
<<<< file: aTest.py
#! /usr/bin/env python
import imp
import A
name='B'
fp, pathname, description = imp.find_module(name)
B=imp.load_module(name, fp, pathname, description)
a=A.A(1)
b=B.B()
 >>>>

<<<< file: A.py
class A:
     a=None
     def __init__(self,a=None):
         if (a):
             A.a=a
     def __str__(self):
         return str(A.a)
 >>>>

<<<< file: B.py
import A
class B:
     def __init__(self):
         a=A.A()
         print a
 >>>>

Execution:
$ ./aTest.py
1

The value 1 obtained as expected (A.a is a static value and keept as such).

If now I just *rename* file B to B.1, without any change in the code 
(except name='B' become name='B.1' in aTest.py), content of B.1.py file 
being exacty the same as content of B.py, I get:

$ ./aTest.py
None

Renaming B.py to B.1.py made A unable to keeps the value of it's static 
variable.

Bug tested with:
Python 1.5.2
Python 2.2.2
Python 2.3.3

Any idea ? Is it well a bug ? Some feature I didnt understood ? I read 
about submodule naminig using dots as separator, but I cant relate it 
towhat I saw here.

Thanks.

	Yannick

-- 
_/ Yannick Patois \___________________________________________________
| web: http://feelingsurfer.net/garp/ | Garp sur irc undernet          |
| email:  patois at calvix.org           |                                |
| ATTAC dans le Pays de Gex: http://attacgex.ouvaton.org               |



More information about the Python-list mailing list