Python3从函数用例返回字典
我有一个python函数,它应该返回单词:Python3从函数用例返回字典,python,function,Python,Function,我有一个python函数,它应该返回单词: def load_cred(FILE): key_for_enc = getpass(prompt='Key for encrypted credentials file: ', stream=None) cipher = AESCipher(key_for_enc) crd_dict={} with open(FILE, 'r') as fh: for line in fh: d
def load_cred(FILE):
key_for_enc = getpass(prompt='Key for encrypted credentials file: ', stream=None)
cipher = AESCipher(key_for_enc)
crd_dict={}
with open(FILE, 'r') as fh:
for line in fh:
dec_line = cipher.decrypt(line)
# print("line: {}".format(dec_line))
dec_line.strip()
start_string, user, password = dec_line.split(10*'|')
crd_dict[start_string] = (user, password)
#print("1: {} 2: {} 3: {}".format(start_string,user,password))
print("crd diction: {}".format(crd_dict))
return crd_dict
但当我从其他脚本中调用它时:
Data_cred = load_cred(CRED_FILE)
print ("Data type: {}".format(type(Data_cred)))
print("Data: ".format(Data_cred))
返回的字典不显示为返回值。。。有人能帮我吗?请注意,在函数load_cred中,crd_dict有它的项。。但在外面它没有。我还是不明白为什么
Key for encrypted credentials file:
crd diction: {'first_line': ('User1', 'Pass1')}
Data type: <class 'dict'>
Data len:
Data:
加密凭据文件的密钥:
crd用语:{'first_line':('User1','Pass1')}
数据类型:
数据长度:
数据:
函数load\u cred()
正在返回字典。打印时忘记在最后一行添加替换字段-
print("Data: {}".format(Data_cred))
函数
load\u cred()
正在返回字典。打印时忘记在最后一行添加替换字段-
print("Data: {}".format(Data_cred))