•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 456,592 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,529 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 720 | Replies: 3
![]() |
| |
•
•
Join Date: Oct 2006
Location: Ohio
Posts: 55
Reputation:
Rep Power: 3
Solved Threads: 0
I have been trying to figure out how to create a custom save script for text games and a text editor that I am working on. I was thinking I would have to have the script write to the actual program, unless I had an extra file just for saves. Which would be the best route, if any of these two at all?
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Here's an example in which the user types in text which is then saved to a file:
If you use this method, the second time you run the program it will overwrite the text you saved before; as it's writing to the same file. If you're making a text editor you'll need to implement a save dialog box that lets you choose where to save it so that this doesn't happen; how you can do that depends on what GUI module you use.
python Syntax (Toggle Plain Text)
## The save function def SaveText(text): filepath = "Your filepath eg. C:\\Random files\\New text.txt" # Open the file first (this creates the file if it doesn't exist already) # It takes two variables; the file to save to (must contain the file # extension) and a string which can be "r", "w" or "r+". In this case # use "w", which means "write". infile = open("filepath", "w") # Write the text infile.write(text) # Close the file infile.close() print "Text saving demonstration" text = raw_input("Enter some text: ") SaveText(text) print "Saved"
AHAHAHA, I'm such a 1337 haxxor! Whoever's at 127.0.0.1 just got their hard disk erased!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- "package" java instruccion in python? (Python)
- Rpg (Python)
- "Save Target As.." isn't working in IE6 (Web Browsers)
- The "print" function prints the whole code page (PHP)
- document.write to new window and into a 3 column table! Help Please! (JavaScript / DHTML / AJAX)
- page set-up to print 4"x6" windows xp (Windows NT / 2000 / XP / 2003)
- IE "Save Image as;" Bitmap, wont in JPEG??? (Web Browsers)
Other Threads in the Python Forum
- Previous Thread: Noob needs help i/o file data
- Next Thread: Capture stdin output from popen2


Hybrid Mode