所以我一直在研究神圣的东西,它看起来很棒。不幸的是,我没有找到任何像我试图实现的多文件用例示例。
所以我有一个名为 configuration.py 的文件,它旨在包含不同的变量,这些变量将(使用神圣)插入到代码的其余部分(放置在不同的文件中):
from sacred import Experiment
ex = Experiment('Analysis')
@ex.config
def configure_analysis_default():
"""Initializes default """
generic_name = "C:\\basic_config.cfg" # configuration filename
message = "This is my generic name: %s!" % generic_name
print(message)
@ex.automain #automain function needs to be at the end of the file. Otherwise everything below it is not defined yet
# when the experiment is run.
def my_main(message):
print(message)
这本身就很好用。神圣按预期工作。但是,当我尝试引入第二个名为 Analysis.py 的文件时:
import configuration
from sacred import Experiment
ex = Experiment('Analysis')
@ex.capture
def what_is_love(generic_name):
message = " I don't know"
print(message)
print(generic_name)
@ex.automain
def my_main1():
what_is_love()
运行 Analysis.py 产生:
错误:
TypeError:what_is_love 缺少 ['generic_name'] 的值
我希望“导入配置”语句包含 configuration.py 文件,从而导入其中配置的所有内容,包括 configure_analysis_default() 及其装饰器 @ex.config,然后将其注入 what_is_love(generic_name)。我究竟做错了什么?我怎样才能解决这个问题?
欣赏它!