有没有办法在python中读/写没有节头的配置文件?

Rob*_*Rob 1 python

我想使用 python 修改 hostapd 配置文件

#
# Wireless Interface
#
interface=wlp2s0
driver=nl80211
#
# Wireless Environment
#
# Currently not working due to
# regulatory restrictions on 5GHz wifi
# in driver
#
ssid=bobthebuilder
hw_mode=a
ieee80211d=1
country_code=GB
channel=40
ieee80211n=1
Run Code Online (Sandbox Code Playgroud)

(等等)

但是configparser库需要使用配置部分的头文件 - 我们还有另一个库可以用来编辑这个文件吗?

Håk*_*Lid 6

似乎是一个非常简单的配置文件语法。为什么不编写自己的配置解析器?

conf = {}
with open('config.cfg') as fp:
  for line in fp:
    if line.startswith('#'):
      continue
    key, val = line.strip().split('=')
    conf[key] = val
Run Code Online (Sandbox Code Playgroud)