Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从脚本执行runpy.run_路径时出错_Python_Runpy - Fatal编程技术网

Python 从脚本执行runpy.run_路径时出错

Python 从脚本执行runpy.run_路径时出错,python,runpy,Python,Runpy,我有一个小python文件c:\tmp\server\u 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")

我有一个小python文件
c:\tmp\server\u 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\u path(“c:\\tmp\\server\u config.py”)
时,我得到以下回溯:

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)