Python reads the configuration file error: raise NoSectionError (section) from None

I. Description of the problem

When reading the configuration file using configparser.ConfigParser (), an error

  File "D:\Sets\Python38-32\lib\configparser.py", line 1149, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'RegisterElement'

Second, the problem is solved

Here are three kinds of solutions, much the same

(1) a first: with the code read path


# 读取程序文件所在目录绝对路径
path = os.path.dirname(os.path.abspath(__file__))
r_i = ReadIni(path+"/LocalElement.ini")

or

r_i = ReadIni("LocalElement.ini")

Location of files and programs
Here Insert Picture Description

(2) The second: Fill in absolute direct path

In fact, the first and second almost, in essence, is the absolute path to read and write in advance

 r_i = ReadIni("D:/Workspaces/Pworkspace/LocalElement.ini")

(3) Third: relative path

r_i = ReadIni("../LocalElement.ini")

Location and program files
Here Insert Picture Description

Published 59 original articles · won praise 6 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_27009225/article/details/104623074