how to “source” file into python script

后端 未结 7 994
孤街浪徒
孤街浪徒 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

    Keep in mind that if you have a "text" file with this content that has a .py as the file extension, you can always do:

    import mytextfile
    
    print(mytestfile.FOO)
    

    Of course, this assumes that the text file is syntactically correct as far as Python is concerned. On a project I worked on we did something similar to this. Turned some text files into Python files. Wacky but maybe worth consideration.

    0 讨论(0)
提交回复
热议问题