Package name with '.' in them: Python Bug ?
John Roth
newsgroups at jhrothjr.com
Fri Mar 19 15:38:49 EST 2004
"Yannick Patois" <patois at calvix.org> wrote in message
news:c3f1ac$n29$1 at sunnews.cern.ch...
> Hi,
>
> Under some naming conditions of module files, it seems that python lost
> class static variables values.
There is no such thing as a static variable in Python.
> 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):
There is no such thing as a static variable in Python.
> 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:
[...]
"B.1" is not a legal file name from an import perspective. The manual
description for find_module says: "The function does not handle hierarchical
module names (names containing dots)."
John Roth
>
> Thanks.
>
> Yannick
>
More information about the Python-list
mailing list