Properties file in python (similar to Java Properties)

后端 未结 25 2791
故里飘歌
故里飘歌 2020-11-29 17:41

Given the following format (.properties or .ini):

propertyName1=propertyValue1
propertyName2=propertyValue2
...
propertyNam         


        
25条回答
  •  温柔的废话
    2020-11-29 18:44

    you can use parameter "fromfile_prefix_chars" with argparse to read from config file as below---

    temp.py

    parser = argparse.ArgumentParser(fromfile_prefix_chars='#')
    parser.add_argument('--a')
    parser.add_argument('--b')
    args = parser.parse_args()
    print(args.a)
    print(args.b)
    

    config file

    --a
    hello
    --b
    hello dear
    

    Run command

    python temp.py "#config"
    

提交回复
热议问题