包名称中包含'。':Python Bug? [英] Package name with '.' in them: Python Bug ?

查看:59
本文介绍了包名称中包含'。':Python Bug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在模块文件的某些命名条件下,似乎python丢失了

类静态变量值。

似乎只在导入严重时附加。命名模块

本身导入一个带有静态变量的模块(看起来很复杂,但是

见下面的例子,很简单):

首先是一个工作示例:

<<<< file:aTest.py

#! / usr / bin / env python

import imp

import A

name =''B''

fp,pathname,description = imp.find_module(name)

B = imp.load_module(名称,fp,路径名,描述)

a = AA(1)
b = BB()

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()



<<<<文件:A.py

A类:

a =无

def __init __(自我,a =无):

如果(a):

Aa = a

def __str __(自我):

返回str(Aa)


<<<<文件:B.py

导入A

B级:

def __init __(个体经营):

a = AA ()

打印

<<<< 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




执行:

$ ./aTest .py

1


按预期获得的值1(Aa是一个静态值并且保持不变)。


如果现在我只是*将文件B重命名为B.1,代码没有任何变化

(除了名字='''B''变成名字='''B.1'''在aTest.py)中,B.1.py文件的内容

与B.py的内容完全相同,我得到:


$。 /aTest.py

没有


将B.py重命名为B.1.py使A无法保持它的静态值

变量。


错误测试:

Python 1.5.2

Python 2.2.2

Python 2.3.3


有什么想法吗?这是一个错误吗?我不明白的一些功能?关于使用点作为分隔符的submodule naminig,我读了

,但我无法将它关联起来

我在这里看到的。


谢谢。


Yannick


-

_ / Yannick Patois \ _________________________________________________ __

|网站: http://feelingsurfer.net/garp/ | Garp sur irc undernet |

|电子邮件: pa****@calvix.org | |

| ATTAC dans le Pays de Gex: http://attacgex.ouvaton.org |



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: pa****@calvix.org | |
| ATTAC dans le Pays de Gex: http://attacgex.ouvaton.org |

推荐答案

./ aTest.py

1


按预期获得的值1 (Aa是一个静态值,因此也是如此)。


如果现在我只是*将文件B重命名为B.1,代码没有任何变化

(除了name =''B''在aTest.py中成为name =''B.1''),B.1.py文件的内容

与内容相同B.py,我得到:

./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




将B.py重命名为B.1.py使A无法保持它的值静态

变量。


错误测试:

Python 1.5.2

Python 2.2.2

Python 2.3.3


Any想法?这是一个错误吗?我不明白的一些功能?关于使用点作为分隔符的submodule naminig,我读了

,但我无法将它关联起来

我在这里看到的。


谢谢。


Yannick


-

_ / Yannick Patois \ _________________________________________________ __

|网站: http://feelingsurfer.net/garp/ | Garp sur irc undernet |

|电子邮件: pa****@calvix.org | |

| ATTAC dans le Pays de Gex: http://attacgex.ouvaton.org |
./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: pa****@calvix.org | |
| ATTAC dans le Pays de Gex: http://attacgex.ouvaton.org |




" Yannick Patois" < PA **** @ calvix.org>在消息中写道

news:c3 ********** @ sunnews.cern.ch ...

"Yannick Patois" <pa****@calvix.org> wrote in message
news:c3**********@sunnews.cern.ch...

在模块文件的某些命名条件下,似乎python丢失了类静态变量值。


由于''静态变量''不是Python的概念,我不知道你的b $ b是什么意思。

它似乎只是在导入严重时附加命名模块
本身导入一个带有静态变量的模块(看起来很复杂,但是看看下面的例子,非常简单):

首先是一个工作示例:
<<<< file:aTest.py
#! / usr / bin / env python
导入imp
导入A
name ='''B''
fp,pathname,description = imp.find_module(name)
B = imp.load_module(名称,fp,路径名,描述)
a = AA(1)
b = BB()
Hi,

Under some naming conditions of module files, it seems that python lost
class static variables values.
Since ''static variable'' is not a Python concept, I do not know what you
mean.
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()
> ;>>>
<<<<文件:A.py
A类:
a =无
def __init __(自我,a =无):
如果(a):
Aa = a
def __str __(self):
return str(Aa)>>>>
<<<<文件:B.py
导入A
B类:
def __init __(个体经营):
a = AA()
打印>>>> ;
>>>>
<<<< 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:


这篇关于包名称中包含'。':Python Bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆