在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) –