在Python中,是否有可能带有一些参数导入模块?
我所指的“参数”是指模块中存在一个未在该模块中初始化的变量,但我仍在该模块中使用该变量。简而言之,我想要类似函数的行为,但与函数不同的是,我希望模块的变量在调用代码中被公开。
例如a.py
:
#lists like data, count, prob_distribution are constructed from training_pool (not initialized in this file)
x = pymc.Uniform('x', lower = 0, upper = 1)
rv = [ Multinomial("rv"+str(i), count[i], prob_distribution[i], value = data[i], observed=True) for i in xrange(0, len(count)) ]
b.py
:
import a #I want some way tr pass value of training_pool
m = pymc.MCMC(a)
我希望a.py
中的所有随机变量都能暴露给MCMC
。对于手头问题,我也愿意接受更好的方法,但我也想知道在Python中是否可以将参数传递给模块。
from a import *
吗? - BrenBarn