I understand how to actually link python files, however, i don't
understand how to get variable's from these linked files. I've tried
to grab them and I keep getting NameError.
你怎么做到的?发布更多代码。例如,以下工作:
文件1.py
#!/usr/bin/env python
from file2 import file2_func, file2_variable
file2_func()
print file2_variable
文件2.py:
^{pr2}$
Also, in the imported python script, do i have to import everything
again?
不,应该在python解释器读取该文件时导入模块。在
Another question, do i use the self function when using another
scripts functions?
你怎么做到的?发布更多代码。例如,以下工作:
文件1.py
文件2.py:
^{pr2}$不,应该在python解释器读取该文件时导入模块。在
不,这通常是为了访问类成员。见python self explained。在
导入文件的方法也不止一种。请参阅另一个答案以了解一些解释。在
我想你想问的是如何从on.py文件访问全局变量,而不必处理名称空间。在
改为在cd1>中调用
理想情况下,你要保持现有的代码。但是,只需使用importedpyfile命名空间引用这些全局变量。在
例如
^{pr2}$Python模块在C/C++链接库的意义上不是“链接”为可执行文件。Pythonimport操作创建一个引用导入模块的名称;没有这个名称,就没有(直接)访问另一个模块的方法。在
相关问题 更多 >
编程相关推荐