经典方法:

https://docs.python.org/3/library/configparser.html

最简单的方法:

  1. 新建一个.py文件例如:input_keyword.py

    1. # test/input_keyword.py
    2. # python的配置文件
    3. # 形式:key=value
    4. name='知识图谱'
    5. startTime=2010
    6. endTime=2019
    7. currentpage=2
  2. 在另一个.py文件(test_properties.py)中import,文件:input_keyword.py ```python

    test/test_properties.py

    引入python配置文件input_keyword.py

    import input_keyword

直接通过input_keyword.key的方式获取value值

print(input_keyword.name)

  1. 3. 显示结果:
  2. ```bash
  3. F:\MyCode\git_repositories\spider\fund_from_LetPub\venv\Scripts\python.exe F:/MyCode/git_repositories/spider/fund_from_LetPub/test/test_properties.py
  4. 知识图谱
  5. Process finished with exit code 0

附录

input_keyword.py文件

image.png

test_properties.py文件及结果

image.png