Best way to retrieve variable values from a text file?

后端 未结 10 2171
再見小時候
再見小時候 2020-11-30 19:44

Referring on this question, I have a similar -but not the same- problem..

On my way, I\'ll have some text file, structured like:

var_a: \'home\'
var_         


        
10条回答
  •  离开以前
    2020-11-30 20:24

    But what i'll love is to refer to the variable direclty, as i declared it in the python script..

    Assuming you're happy to change your syntax slightly, just use python and import the "config" module.

    # myconfig.py:
    
    var_a = 'home'
    var_b = 'car'
    var_c = 15.5
    

    Then do

    from myconfig import *
    

    And you can reference them by name in your current context.

提交回复
热议问题