读取cfg文件(读取文件的每行内容)

读取的文件:

[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky

# Downsample

[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=leaky

读取上面文件的代码:

file = open(file, 'r')
lines = file.read().split('/n')
#相比file.readlines()会自动去掉换行符

lines = [x for x in lines if len(x) > 0]
#去掉空白字符串

lines = [x for x in lines if x[0] != '#']
#去掉#xxxx行
#得到'='两边字符串
key, value = line.split('=')

 

你可能感兴趣的:(python基础)