Is there any way to save to progress of a Python Program onto an I.P. Address or Harddrive? Like if you enter '5' into a program that multiplies your number by 3 and save it, your saved number would be 'x' when you reopen the file. I need help! :)
Norbert X
42
Junior Poster in Training
Recommended Answers
Jump to PostYeah there sure is
#use the current directory or absolute path f = open("File.txt",'w') #write mode 'w' answer = 5*3 #make a string, only stings can be added to files answer = str(answer) f.write(answer) f.close() #then open it back up o = open("File.txt",'r') #read mode 'r' print …
Jump to PostI have a solution which allows you to use a persistent dictionary between different excecutions of your program, using the with statement (python >= 2.5). Here is an exemple program:
from __future__ import with_statement from persistent import PersistentDict def main(pdict): if not 'x' in pdict: pdict['x'] = …
Jump to PostYou can use pickle, that is useful because it saves the data as it is, so if you have a class you can save the class, and then you load it and it is exactly the same as it was when you saved it.
For that you would need …
All 9 Replies
Norbert X
42
Junior Poster in Training
lllllIllIlllI
178
Veteran Poster
Gribouillis
1,391
Programming Explorer
Team Colleague
Norbert X
42
Junior Poster in Training
lllllIllIlllI
178
Veteran Poster
Norbert X
42
Junior Poster in Training
lllllIllIlllI
178
Veteran Poster
Norbert X
42
Junior Poster in Training
leegeorg07
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.