I am working on some software to use across multiple computers, and has an FTP server that will be created using the library pyftpdlib
to use for downloading needed files from the "manager". While I am setting up the authorization for it, I ran across the issue of how to get a value from a list, in my param
dictionary, that is filled from a file named config.json
. Here is my code below for if the file does not exist:
if not os.path.exists("config.json"):
name = socket.gethostname()
ip = socket.gethostbyname(name)
params['ip'] = []
params['ftp_creds'] = []
params['output_directory'] = []
params['ip'].append({
'address': str(ip)
})
params['ftp_creds'].append({
'username': 'root',
'password': '12345',
'directory': 'ftp_files'
})
params['output_directory'].append({
'output-directory': 'render_out'
})
with open("config.json","w") as file:
json.dump(params, file)
print("File config.json did not exist, wrote it. Please restart script.")
sys.exit()
Down further in the script, I have a couple lines of code setting up the "authorizer" that are a work in progress.
ftp_authorizer = DummyAuthorizer()
ftp_authorizer.add_user(perm="elradfmwMT")
The perm="elradfmwMT"
argument will not be the only argument, as I will be getting values from the dictionary to set up username, password, etc.
Any ideas?
question from:
https://stackoverflow.com/questions/65947538/python-get-value-from-list-in-dictionary 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…