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_modu le(name, fp, pathname, description)
a=A.A(1)
b=B.B()[color=blue][color=green][color=darkred]
>>>>[/color][/color][/color]
<<<< file: A.py
class A:
a=None
def __init__(self,a =None):
if (a):
A.a=a
def __str__(self):
return str(A.a)[color=blue][color=green][color=darkred]
>>>>[/color][/color][/color]
<<<< file: B.py
import A
class B:
def __init__(self):
a=A.A()
print a[color=blue][color=green][color=darkred]
>>>>[/color][/color][/color]
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@calvix.o rg | |
| ATTAC dans le Pays de Gex: http://attacgex.ouvaton.org |
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_modu le(name, fp, pathname, description)
a=A.A(1)
b=B.B()[color=blue][color=green][color=darkred]
>>>>[/color][/color][/color]
<<<< file: A.py
class A:
a=None
def __init__(self,a =None):
if (a):
A.a=a
def __str__(self):
return str(A.a)[color=blue][color=green][color=darkred]
>>>>[/color][/color][/color]
<<<< file: B.py
import A
class B:
def __init__(self):
a=A.A()
print a[color=blue][color=green][color=darkred]
>>>>[/color][/color][/color]
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@calvix.o rg | |
| ATTAC dans le Pays de Gex: http://attacgex.ouvaton.org |
Comment