암호 관리자 역할을하는 .txt 파일에서 암호를 추가/변경/검색하기위한 스크립트를 만들려고합니다.파이썬 스크립트 작성 후 .txt 파일이 비어 있습니다. -/- 해독 키 전달
질문의 역사를 조사 할 때 대부분의 사용자는 flush()
또는 close()
파일 스트림을 잊어 버린 것으로 보입니다.
theList = {}
# Populates theList with pairs
def getData():
with open('pass_data.txt', 'w+') as data:
for line in data:
keyValuePair = line.split()
theList[keyValuePair[0]] = keyValuePair[1]
# Writes pairs from theList to file 'pass_data.txt'
def putData():
with open('pass_data.txt', 'w+') as data:
for k, v in theList.items():
data.writelines([k, ' ', v, "\n"])
data.flush()
# Appends new pair to theList or overwrites if already exists
def setPass(service, password):
getData()
theList[service] = password
putData()
# Retrieves password from given key 'service'
def getPass(service):
getData()
print theList[service]
나는이 문제에 독서 후 flush()
을 추가하고 내 .txt 인은 여전히 비어 있습니다 ... 차이를하지 않으며이 더가 말한다 때문에 명령 줄에서 함수를 호출하지 getPass('service')
때 키 값 'service'.
다른 사람이 나에게도 대답 할 수있는 두 번째 질문이 있습니다.vim에서 복어로 pass_data.txt 파일을 암호화 한 경우 setPass()
및 getPass()
에 대한 인수로 파일의 암호를 해독 할 수있는 방법이 있습니까? docs 가입일
대단히 감사합니다. 이것은 내 문제를 해결하지만 두 번째 질문에 대한 가시성을 위해 몇 시간 동안 미해결로 표시합니다. – aweeeezy