在bash中,我有一个以变量格式存储我的密码的文件。Python - 从文件中读取变量的值
例如
cat file.passwd
password1=EncryptedPassword1
password2=EncryptedPassword2
现在,如果我想使用的password1
的价值,这是所有我需要在bash做。
grep password1 file.passwd | cut -d'=' -f2
我在找python的替代方法。是否有任何库提供了简单的提取值的功能,或者我们必须像下面那样手动执行这个功能: ?
with open(file, 'r') as input:
for line in input:
if 'password1' in line:
re.findall(r'=(\w+)', line)
[解析文本文件中的键值对]可能的副本(http://stackoverflow.com/questions/9161439/parse-key-value-pairs-in-a-text-file) –