1

I have a small python file c:\tmp\server_config that defines a dictionary as follows:

conf = {'server1':'11.27.32.99',
        'server2':'11.27.44.42'}

I wish to access this dictionary from within another script. I can execute the following from the command line:

>>> 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'}

But however when I try to execute settings = run_path("c:\\tmp\\server_config.py") from within another script I get the following 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'

What am I doing wrong (Python 3.7, Windows10)?

Jochen Schwarze
  • 292
  • 6
  • 27
  • did you digure this one out I have problems as well, the modules inside the script I am calling are not recognized – KZiovas Sep 29 '21 at 09:49

0 Answers0