0

Can I be able to read a text file from any text editor (eg Ms word, wordpad) using python. and then return whats inside?

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by jlm699
0

Yes. You can use open to open a file and return the file handle. Note that some formats (ie, .doc) are not "flat" text files, meaning they may have some binary data, markup, etc.

You'll need to take that into account on a per-file basis.

0

all I can find in my python books is that I can open a file eg
f = open("filename",'w') and then write to the file using f.write()
and stuff. So how do I open eg a file with file name jag.doc that is stored in my documents folder, how do I specify where the file is located?

0

So how do I open eg a file with file name jag.doc that is stored in my documents folder, how do I specify where the file is located?

To read a file, you use the 'r' (read) mode instead of 'w' (write).

To specify the file's location you can type the absolute path to the file, ie C:\Documents and Settings\<user_name>\My Documents\jag.doc ; however in PYthon \ is an escape character. In light of this you could either use the forward slash / like linux or use a double backslash \\

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.