-1

I have code:

import matplotlib.pyplot as plt
from configparser import ConfigParser  
cfg = ConfigParser()
cfg.read('file.cfg')    
plt.plot([1, 10],[2, 2], color_4, ls = "dashed")   
plt.xlim(1,10)
plt.ylim(1,4)
plt.savefig('image.pdf')

and I would like control it by configuration file:

[a]
color_4 = c = 'silver'

What is wrong please? It gives an error:

NameError: name 'color_4' is not defined
Arrara
  • 173
  • 1
  • 10

1 Answers1

1

I guess you need to get the value in this way to get the value of color_4:

cfg['a']['color_4']

from configparser import ConfigParser  
cfg = ConfigParser()
cfg.read('file.cfg')    
plt.plot([1, 10],[2, 2], cfg['a']['color_4'], ls = "dashed")   
plt.xlim(1,10)
plt.ylim(1,4)
plt.savefig('image.pdf')

Ref: ConfigParser

Sumit S Chawla
  • 3,180
  • 1
  • 14
  • 33