By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,002 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,002 IT Pros & Developers. It's quick & easy.

Question about files?

P: n/a
I want to create a program where a user can type what ever they want
to, have it saved to a file, and the be able to re-open it and read
it. How would I do this? Thanks!
May 31 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On May 31, 3:25*pm, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
On Sat, 31 May 2008 11:44:14 -0700 (PDT), corvettecra...@gmail.com
declaimed the following in comp.lang.python:
I want to create a program where a user can type what ever they want
to, have it saved to a file, and the be able to re-open it and read
it. How would I do this? Thanks!

import os
os.system("edit") * * # may be Windows specific

* * * * Start with:http://www.catb.org/~esr/faqs/smart-questions.html

(or, to expand on it... Exactly what part of the task are you having
problems with? Opening files for read/write/update? Designing a command
set for an editor? Designing a GUI for a text editor; what toolkit, does
it have a generic text edit widget already? Do you really need to write
another text editor when there are so many available that come with most
operating systems (Windows: edit, notepad, maybe even wordpad;
UNIX/Linux type systems: vi, vim, gvim, emacs) or can be downloaded
(SciTE) )

--
* * * * Wulfraed * * * *Dennis Lee Bieber * * * * * * * KD6MOG
* * * * wlfr...@ix.netcom.com * * * * * * *wulfr...@bestiaria.com
* * * * * * * * HTTP://wlfraed.home.netcom.com/
* * * * (Bestiaria Support Staff: * * * * * * * web-a...@bestiaria.com)
* * * * * * * * HTTP://www.bestiaria.com/
No, what I mean is for the user to input text directly into the python
program, then the program would save it to a file and display it after
it is created.
May 31 '08 #2

P: n/a
On 31 Mag, 21:28, corvettecra...@gmail.com wrote:
On May 31, 3:25*pm, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:


On Sat, 31 May 2008 11:44:14 -0700 (PDT), corvettecra...@gmail.com
declaimed the following in comp.lang.python:
I want to create a program where a user can type what ever they want
to, have it saved to a file, and the be able to re-open it and read
it. How would I do this? Thanks!
import os
os.system("edit") * * # may be Windows specific
* * * * Start with:http://www.catb.org/~esr/faqs/smart-questions..html
(or, to expand on it... Exactly what part of the task are you having
problems with? Opening files for read/write/update? Designing a command
set for an editor? Designing a GUI for a text editor; what toolkit, does
it have a generic text edit widget already? Do you really need to write
another text editor when there are so many available that come with most
operating systems (Windows: edit, notepad, maybe even wordpad;
UNIX/Linux type systems: vi, vim, gvim, emacs) or can be downloaded
(SciTE) )
--
* * * * Wulfraed * * * *Dennis Lee Bieber * * * * * * * KD6MOG
* * * * wlfr...@ix.netcom.com * * * * * * *wulfr....@bestiaria.com
* * * * * * * * HTTP://wlfraed.home.netcom.com/
* * * * (Bestiaria Support Staff: * * * * * * * web-a...@bestiaria.com)
* * * * * * * * HTTP://www.bestiaria.com/

No, what I mean is for the user to input text directly into the python
program
You can use raw_input() to ask user to type something, then use open()
to create a file and write in it.
http://docs.python.org/lib/bltin-file-objects.html
then the program would save it to a file and display it after
it is created.
What do you mean by "display"?
Open that file with a text editor? Print the content of the file on
screen?
--- Giampaolo
http://code.google.com/p/pyftpdlib/
May 31 '08 #3

P: n/a
Lie
On Jun 1, 1:44*am, corvettecra...@gmail.com wrote:
I want to create a program where a user can type what ever they want
to, have it saved to a file, and the be able to re-open it and read
it. How would I do this? Thanks!
Use a multi-line text-input widget (available on any widget library)

To open a file in python for reading:
filepointer = file('path/to/file', 'r')

then read it like this:
for line in filepointer:
dosomethingwith(f)

or:
filecontent = filepointer.read()

To open a file for writing:
filepointer = file('path/to/file', 'w')

to write to a file:
filepointer.write(somestring)

Jun 1 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.