Python 配置文件
是否可以将这样的内容写入.cfg文件(=字符串形式的ale) 在另一个文件中查找此文件Python 配置文件,python,python-3.x,matplotlib,configuration,Python,Python 3.x,Matplotlib,Configuration,是否可以将这样的内容写入.cfg文件(=字符串形式的ale) 在另一个文件中查找此文件 plt.plot([1, 10],[2, 2], cfg['styles']['help_lines']) 建议后编辑: plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"] params = {'text.usetex' : True, 'font.size' : 11, 'font.family
plt.plot([1, 10],[2, 2], cfg['styles']['help_lines'])
建议后编辑:
plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"]
params = {'text.usetex' : True,
'font.size' : 11,
'font.family' : 'lmodern',
'text.latex.unicode': True,
}
plt.rcParams.update(params)
如何将其写入myconfig.py以及如何将其包含到script.py?您看过该模块了吗
以下是您可以做的:
- config.ini
[styles] help_lines = silver c = silver ls = dashed
- 用法:
cfg = configparser.ConfigParser() cfg.read('/path/to/config.ini') print(cfg['styles']['help_lines']) # silver
- 请注意,可以使用python文件来实现这一点
myconfig.py
class styles:
helper_lines = dict(c = "silver",
ls = "dashed")
import myconfig as cfg
import matplotlib.pyplot as plt
plt.plot([1,2,3], **cfg.styles.helper_lines)
plt.show()
script.py
class styles:
helper_lines = dict(c = "silver",
ls = "dashed")
import myconfig as cfg
import matplotlib.pyplot as plt
plt.plot([1,2,3], **cfg.styles.helper_lines)
plt.show()
谢谢你,你能帮我修改我的问题吗?