我有一个小的 python 文件c:\tmp\server_config
,它定义了一个字典,如下所示:
conf = {'server1':'11.27.32.99',
'server2':'11.27.44.42'}
我希望从另一个脚本中访问这本字典。我可以从命令行执行以下命令:
>>> from runpy import run_path
>>> settings = run_path("c:\\tmp\\server_config.py")
>>> settings['conf']
{'server1': '11.27.32.99', 'server2': '11.27.44.42'}
但是,当我尝试settings = run_path("c:\\tmp\\server_config.py")
从另一个脚本中执行时,我得到以下 Traceback:
Traceback (most recent call last):
File "", line 1, in
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:/Users/sjo/AppData/Roaming/QGIS/QGIS3/startup.py", line 54, in
settings = run_path('c:\\tmp\\server_config.py')
File "C:\OSGEO4~1\apps\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\OSGEO4~1\apps\Python37\lib\runpy.py", line 93, in _run_module_code
with _TempModule(mod_name) as temp_module, _ModifiedArgv0(fname):
File "C:\OSGEO4~1\apps\Python37\lib\runpy.py", line 54, in __enter__
self._saved_value = sys.argv[0]
AttributeError: module 'sys' has no attribute 'argv'
我在做什么错(Python 3.7,Windows10)?