[英]How to remove the last occurrence of “=” symbol from a property file using Python
這是我的屬性文件的內容,文件名為 conf.properties
#A_Value='true'
#cache_locators='Server_name:1212'
#ssl_trustore='qa_client_truststore'
#ssl_password='ENC(kYE9WAv/HYjdw='=')'
我正在嘗試將此屬性文件轉換為 json
將 conf.properties 轉換為 json 的代碼
import json
import sys
prop_file = "conf.properties"
import pathlib
file = pathlib.Path(prop_file)
if file.exists ():
split_properties=[line.split("=") for line in open(prop_file)]
properties={key: value for key,value in split_properties }
print(json.dumps(properties))
else:
print (prop_file+" not found")
由於config.properties
的最后一行有多個"="
符號,我收到以下錯誤 -
properties={key: value for key,value in split_properties }
ValueError: too many values to unpack (expected 2)
我需要刪除 config.properties 最后一行的“=”符號的多次出現
從
#ssl_password='ENC(kYE9WAv/HYjdw='=')'
至
#ssl_password='ENC(kYE9WAv/HYjdw)'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.