从外部导入的模块访问变量 [英] Access to variable from external imported module
问题描述
如何从模块访问变量(未返回该值)
导入?
并且变量在模块级别设置。 />
该模块在我的程序外部,它来自另一个项目,所以我
不想修改它。
How to access to a variable (that value is not returned) from a module
imported?
And the variable is set at the module-level.
That module is external to my program, it''s from another project so I
wann''t modifying it.
推荐答案
GinTon写道:
GinTon wrote:
如何访问变量(不返回该值)一个模块
导入了什么?
变量是在模块级别设置的。
How to access to a variable (that value is not returned) from a module
imported?
And the variable is set at the module-level.
导入模块
print module.variable
(你读过Python教程吗? )
< / F>
import module
print module.variable
(have you read the Python tutorial?)
</F>
对不起,我的意思是从一个方法访问本地变量/>
导入模块
方法(值)
我将访问在该方法中本地创建的值
Fredrik Lundh ha escrito:
Sorry, I mean access to local variable from a method
import module
method(value)
I would to access to values that are created locally in that method
Fredrik Lundh ha escrito:
GinTon写道:
GinTon wrote:
如何从模块访问变量(未返回该值)
导入?
变量在模块级设置。
How to access to a variable (that value is not returned) from a module
imported?
And the variable is set at the module-level.
导入模块
print module.variable
< / F>
import module
print module.variable
(have you read the Python tutorial?)
</F>
GinTon写道:
GinTon wrote:
对不起,我的意思是从方法访问本地变量
导入模块
方法(值)
我将访问在该方法中本地创建的值方法执行后
Sorry, I mean access to local variable from a method
import module
method(value)
I would to access to values that are created locally in that method
?通常是返回值?
或者你想获得所有局部变量,然后制作一个函数/方法
def f(a = 1):
b = 2
c = 3
返回本地人()#X /对象(本地人())
--- -----
d = module.f()
打印d [''c''] #dc
罗伯特
after the method has executed? usually the return value?
or you want to get all local variables, then make a func/method
def f(a=1):
b=2
c=3
return locals() #X/Object(locals())
--------
d=module.f()
print d[''c''] # d.c
Robert
这篇关于从外部导入的模块访问变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!