对不起,我只是一个python语言的初学者,我很困在这个问题上很长。实际上,我想创建一个由降序和上升。但是我不能让它工作。 python的主文件是pythonaslab.py上升和下降的模块是选择模块.py…代码:
这是选择模块:
import pythonaslab
def ascendingselection():
for q in range(len(b)):
w=q+1
for w in range(len(b)):
if b[q]>b[w]:
f=b[q]
b[q]=b[w]
b[w]=f
print b
def descendingselection():
for q in range(len(b)):
w=q+1
for w in range(len(b)):
if b[q]<b[w]:
f=b[q]
b[q]=b[w]
b[w]=f
print b
这是主文件,Python实验室:
^{pr2}$你能告诉我这些错误的原因在哪里吗?在
Traceback (most recent call last):
File "E:\Coding\pythonaslab.py", line 1, in <module>
import selectionmodule
File "E:\Coding\selectionmodule.py", line 1, in <module>
import pythonaslab
File "E:\Coding\pythonaslab.py", line 16, in <module>
selectionmodule.descendingselection()
AttributeError: 'module' object has no attribute 'descendingselection'
您创建了一个循环导入;您的
pythonaslab
模块导入selectionmodule
,该模块导入pythonaslab
模块。你最终得到的是不完整的模块,不要这样做。在从
selectionmodule
中删除import pythonaslab
行;该模块中没有使用pythonaslab
。在另外,另一个模块无法读取您的全局参数;您需要将它们作为参数传入:
那就叫它:
^{pr2}$请注意,变量名不限于一个字母。使用较长的描述性名称可以使代码更具可读性。在
如果不想使用模块名称,例如:
您应该导入:
^{pr2}$你可以打电话给:
也可以导入模块并指定别名:
更多信息请阅读:import confusaion
相关问题 更多 >
编程相关推荐