469,343 Members | 5,350 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

Windows - create text file - (newb)

Can Python be used to create (and/or open, read, and write) a text file
in Windows (if the path is known) ?

Feb 2 '06 #1
4 1899
"Ernesto" <er*******@gmail.com> writes:
Can Python be used to create (and/or open, read, and write) a text file
in Windows (if the path is known) ?


Yes.

--
Jorge Godoy <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Feb 2 '06 #2
Yes.

To open file:

fp=open(r'C:\directory\filename.txt','r')

To open file to write to:

fp=open(r'C:\directory\filename.txt','w')

You probably need to go through the Python tutorial as
these items are covered.

-Larry Bates


Ernesto wrote:
Can Python be used to create (and/or open, read, and write) a text file
in Windows (if the path is known) ?

Feb 2 '06 #3
Yes. You could do:

Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
fileobj=open('~\myfile.txt','w')
fileobj.write("test")
fileobj.close()
On Windows, for the path to your file, you could write
r'C:\myfile.txt' (if C:\ is a place you can write to.)

also, see the output from
help("open")


Feb 2 '06 #4
got it . thanks tons. i'm doing the tutorial now.

Feb 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by dm3281 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.