Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 8th, 2005, 7:50 PM   #1
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Smile Can python read in word files?

Hi
I am writing a liitle program, that is supposed to read in a file into a songle string. Can python recognize a word file, and if yes, which thingy in the end do I use (like *.txt for NotePad stuff).
Thanks for any help
Fred
Fred is offline   Reply With Quote
Old Mar 8th, 2005, 9:05 PM   #2
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Looks like for text files the extension .txt is most common.
If you create the file, you can put in a marker up front like the word 'text' that your program then recognizes.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 8th, 2005, 9:26 PM   #3
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
With word files I actually meant:
files created in "Word"... --> sry for the misunderstanding
And I just found out, that *.txt does not work for those.
Any ideas, in how to change the document type using python? Would be an interesting project!
Fred is offline   Reply With Quote
Old Mar 8th, 2005, 9:49 PM   #4
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Whoever is interested in it:
I found a way to open and read-in text files written in word:

import win32com.client
import tkFileDialog

# Launch Word
MSWord = win32com.client.Dispatch("Word.Application")
MSWord.Visible = 0 
# Open a specific file
myWordDoc = tkFileDialog.askopenfilename()
MSWord.Documents.Open(myWordDoc)
#Get the textual content
docText = MSWord.Documents[0].Content
Also I'd like to say, that I found it out by myself, I have to be fair, and say it came from somebody better in python than me...
The link to the site is:
http://mail.python.org/pipermail/pyt...il/217741.html

Fred
Fred is offline   Reply With Quote
Old Mar 9th, 2005, 10:06 AM   #5
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Quote:
Originally Posted by Fred
With word files I actually meant:
files created in "Word"... --> sry for the misunderstanding
And I just found out, that *.txt does not work for those.
Any ideas, in how to change the document type using python? Would be an interesting project!
Now I got your drift! Yes, COM will do the trick! I read an article on COM, but can't remember where exactly! Looks like you found it already!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 9th, 2005, 4:00 PM   #6
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Yup!
Google rocks my world!!!
D:
Fred is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC