2

I'm trying to use execfile() function to use a file as config file. The file has only a bunch of variables and values. But when I'm trying to use it in my code, it throws IOError: [Errno 2] No such file or directory

This is my code:

dictionary = {}
execfile("myConfig.cfg", dictionary)
X-Istence
  • 16,324
  • 6
  • 57
  • 74
sidx
  • 640
  • 2
  • 11
  • 28

1 Answers1

0
  1. I would rename myConfig.cfg to myConfig.py.
  2. Be sure that your config file and the file trying to get the data are in the same folder.
  3. myConfig.py

dictionary={'data1':'value1','data2':'value2'}

4.Import the data:

from myConfig import dictionary print dictionary

ppflrs
  • 311
  • 4
  • 11
  • I used this method at first. I wanted a simpler representation of data, thats why I chose execfile method. – sidx Nov 14 '15 at 09:04