如何在python中使用google/gin配置?
首先,我已经按照项目现场的说明进行了操作,但仍然不知道如何使用它。 “我的文件夹”的结构如下:如何在python中使用google/gin配置?,python,Python,首先,我已经按照项目现场的说明进行了操作,但仍然不知道如何使用它。 “我的文件夹”的结构如下: Folder |________use_gin.py |___config.gin |___test.py 在内部使用\u gin.py: import gin @gin.configurable def my_other_func(a, b, c): return a, b, c 内部config.gin: my_other_func.a = -2.9 my_ot
Folder
|________use_gin.py
|___config.gin
|___test.py
在内部使用\u gin.py
:
import gin
@gin.configurable
def my_other_func(a, b, c):
return a, b, c
内部config.gin
:
my_other_func.a = -2.9
my_other_func.b = 9.3
# Comments!
my_other_func.c = 'Oh, Dear.'
我使用test.py调用my_other_func
函数,它给出错误:
C:/Anaconda3/envs/py3/python.exe d:/Folder/test.py
Traceback (most recent call last):
File "d:/Folder/test.py", line 3, in <module>
my_other_func()
File "C:\Anaconda3\Anaconda3\envs\py3tf\lib\site-packages\gin\config.py", line 1032, in wrapper
utils.augment_exception_message_and_reraise(e, err_str)
File "C:\Anaconda3\Anaconda3\envs\py3tf\lib\site-packages\gin\utils.py", line 48, in augment_exception_message_and_reraise
six.raise_from(proxy.with_traceback(exception.__traceback__), None)
File "<string>", line 3, in raise_from
File "C:\Anaconda3\Anaconda3\envs\py3tf\lib\site-packages\gin\config.py", line 1009, in wrapper
return fn(*new_args, **new_kwargs)
TypeError: my_other_func() missing 3 required positional arguments: 'a', 'b', and 'c'
No values supplied by Gin or caller for arguments: ['a', 'b', 'c']
Gin had values bound for: []
Caller supplied values for: []
In call to configurable 'my_other_func' (<function my_other_func at 0x00000000029C8268>)
C:/Anaconda3/envs/py3/python.exe d:/Folder/test.py
回溯(最近一次呼叫最后一次):
文件“d:/Folder/test.py”,第3行,在
my_other_func()
包装器中的文件“C:\Anaconda3\Anaconda3\envs\py3tf\lib\site packages\gin\config.py”,第1032行
utils.augment\u exception\u message\u和\u reraise(e,err\u str)
文件“C:\Anaconda3\Anaconda3\envs\py3tf\lib\site packages\gin\utils.py”,第48行,在增强异常消息中
六.从(代理.带回溯(例外.\uuu回溯),无)引发回溯
文件“”,第3行,从
包装器中的文件“C:\Anaconda3\Anaconda3\envs\py3tf\lib\site packages\gin\config.py”,第1009行
返回fn(*新参数,**新参数)
TypeError:my_other_func()缺少3个必需的位置参数:“a”、“b”和“c”
Gin或调用者没有为参数提供值:['a','b','c']
Gin的值绑定为:[]
调用方为:[]提供的值
调用可配置的“我的其他函数”()
我的设置有问题吗?在使用
my\u other\u func()
之前,您应该只在test.py中执行
阅读更多详细信息。在使用
my\u other\u func()
之前,您应该只在test.py中执行
阅读更多详细信息。congig.gin
import use_gin
my_other_func.a = -2.9
my_other_func.b = 9.3
# Comments!
my_other_func.c = 'Oh, Dear.'
test.py
import gin
gin.parse_config_file('config.gin')
import use_gin
print(use_gin.my_other_func())
用杜松子酒
import gin
@gin.configurable
def my_other_func(a, b, c):
return a, b, c
杜松子酒
import use_gin
my_other_func.a = -2.9
my_other_func.b = 9.3
# Comments!
my_other_func.c = 'Oh, Dear.'
test.py
import gin
gin.parse_config_file('config.gin')
import use_gin
print(use_gin.my_other_func())
用杜松子酒
import gin
@gin.configurable
def my_other_func(a, b, c):
return a, b, c