使用configparser库写ini文件时,每次添加section,都会与前面obtion空一行,怎么设置才能不出现空行呢
[Match]上面的空行怎么去掉呢?
下面是ini文件的代码部分
import configparser
# 读取配置文件
config = configparser.ConfigParser()
config.read("IpConfig.ini")
# 写入学校配置文件
try:
config.add_section("School") # 添加节School
config.set("School", "IP", "192.168.1.120")
config.set("School", "Mask", "255.255.255.0")
config.set("School", "GateWay", "192.168.1.1")
config.set("School", "DNS", "211.82.96.1")
except configparser.DuplicateSectionError:
print("Section 'School' already exists")
# 写入比赛配置文件
try:
config.add_section("Match")
config.set("Match", "IP", "172.17.29.120")
config.set("Match", "Mask", "255.255.255.0")
config.set("Match", "GateWay", "172.17.29.1")
config.set("Match", "DNS", "0.0.0.0")
except configparser.DuplicateSectionError:
print("Section 'Match' already exists")
# 写入配置文件
config.write(open("IpConfig.ini", "w"))