我正在尝试用 python 2.6 替换文件中的一些文本
但是,它返回一个额外的换行符,这是我的代码:
for line in fileinput.input('/etc/php5/apache2/php.ini', inplace=True):
replace = re.sub(r'(post_max_size =).[0-9]+(M)', r'\1 64\2', line)
print replace
输入:
post_max_size = 6M
sdfsdfsd
post_max_size = 4M
sdfsdf
post_max_size = 164M
dfsdfsdfsdfsdf
输出:
post_max_size = 64M
sdfsdfsd
post_max_size = 64M
sdfsdf
post_max_size = 64M
dfsdfsdfsdfsdf