how to “source” file into python script

后端 未结 7 1013
孤街浪徒
孤街浪徒 2020-12-10 11:39

I have a text file /etc/default/foo which contains one line:

FOO=\"/path/to/foo\"

In my python script, I need to reference the

7条回答
  •  悲哀的现实
    2020-12-10 12:13

    Same answer as @jil however, that answer is specific to some historical version of Python.

    In modern Python (3.x):

    exec(open('filename').read())
    

    replaces execfile('filename') from 2.x

提交回复
热议问题