Answer to Question #232705 in Python for mulanga

Question #232705

Our users do not want to have to re-enter the price levels each time the app starts.

Therefor, we need to save the price levels to a file on disk – called levelsFile - and populate the levelsList with the file’s items when the app starts.


1
Expert's answer
2021-09-03T00:09:53-0400
import pickle
# For example, a list of price levels
price_levels = [1,2,3,4,5]
# Price level list entry file
with open('levelsFile','wb') as f:
    pickle.dump(price_levels, f)
# Reading a list of price levels from a file
with open('levelsFile','rb') as f:
    price_levels_load = pickle.load(f)
# 
print(price_levels_load)
# These operations of writing and reading to a file can 
# be performed from different programs

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS