13 Replies - 13138 Views - Last Post: 08 February 2011 - 09:56 AM Rate Topic: -----

#1 wisam abbasi  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 72
  • Joined: 12-December 09

MS word file and python

Posted 07 February 2011 - 09:01 AM

I need to know how to read a Microsoft word file using python. Can any one help?
Is This A Good Question/Topic? 0
  • +

Replies To: MS word file and python

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10488
  • View blog
  • Posts: 38,873
  • Joined: 27-December 08

Re: MS word file and python

Posted 07 February 2011 - 09:05 AM

See this tutorial on working with files in Python.
Was This Post Helpful? 0
  • +
  • -

#3 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: MS word file and python

Posted 07 February 2011 - 09:09 AM

I would check Pyuno which works with open office. That will be fine for .doc files and .docx files.

This post has been edited by atraub: 07 February 2011 - 09:15 AM

Was This Post Helpful? 0
  • +
  • -

#4 wisam abbasi  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 72
  • Joined: 12-December 09

Re: MS word file and python

Posted 07 February 2011 - 09:13 AM

View Postmacosxnerd101, on 07 February 2011 - 09:05 AM, said:


Thanks alot, but there is nothing in that tutorial about Microsoft word files, it's about text files in general.
can any one help?
Was This Post Helpful? 0
  • +
  • -

#5 wisam abbasi  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 72
  • Joined: 12-December 09

Re: MS word file and python

Posted 07 February 2011 - 09:57 AM

View Postatraub, on 07 February 2011 - 09:09 AM, said:

I would check Pyuno which works with open office. That will be fine for .doc files and .docx files.


It is a really good site, but unfortunately does not contain what I need
Was This Post Helpful? 0
  • +
  • -

#6 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: MS word file and python

Posted 07 February 2011 - 10:01 AM

What is it missing?
Was This Post Helpful? 0
  • +
  • -

#7 wisam abbasi  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 72
  • Joined: 12-December 09

Re: MS word file and python

Posted 07 February 2011 - 10:10 AM

View Postatraub, on 07 February 2011 - 10:01 AM, said:

What is it missing?

I need to read from ms word files not to create and save files
Was This Post Helpful? 0
  • +
  • -

#8 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: MS word file and python

Posted 07 February 2011 - 11:03 AM

This task really is better suited for VB.net... May I ask why you're trying to read .doc/x files with Python?


EDIT:
Actually, I'm seeing stuff that suggests that PyUno can read the files.

This post has been edited by atraub: 07 February 2011 - 11:29 AM

Was This Post Helpful? 0
  • +
  • -

#9 wisam abbasi  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 72
  • Joined: 12-December 09

Re: MS word file and python

Posted 08 February 2011 - 09:40 AM

View Postatraub, on 07 February 2011 - 11:03 AM, said:

This task really is better suited for VB.net... May I ask why you're trying to read .doc/x files with Python?


EDIT:
Actually, I'm seeing stuff that suggests that PyUno can read the files.

It's one of the tasks that must be provided by my graduation project. It is an Automatic text summerizer, and I'm doing it with Python.
Was This Post Helpful? 0
  • +
  • -

#10 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: MS word file and python

Posted 08 February 2011 - 09:42 AM

Have you considered using a combination of VB.net and Iron Python? You can use VB.net to read the files and get the text strings (it also does some nice GUI's very easily) and then use Python to do the summarization.

This post has been edited by atraub: 08 February 2011 - 09:44 AM

Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: MS word file and python

Posted 08 February 2011 - 09:46 AM

You could leverage COM: http://oreilly.com/c...apter/ch12.html
Was This Post Helpful? 1
  • +
  • -

#12 wisam abbasi  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 72
  • Joined: 12-December 09

Re: MS word file and python

Posted 08 February 2011 - 09:50 AM

View Postatraub, on 08 February 2011 - 09:42 AM, said:

Have you considered using a combination of VB.net and Iron Python? You can use VB.net to read the files and get the text strings (it also does some nice GUI's very easily) and then use Python to do the summarization.


I've found this code today

from sys import argv
docdir = 'C:\\temp\\'
if len(argv) == 2: docdir = argv[1]              # ex: comclient.py a:\

from win32com.client import Dispatch             # early or late binding
word  = Dispatch('Word.Application')             # connect/start Word
word.Visible = 1                                 # else Word runs hidden

# create and save new doc file
newdoc = word.Documents.Add( )                       # call Word methods
spot   = newdoc.Range(0,0)
spot.InsertBefore('Hello COM client world!')     # insert some text
newdoc.SaveAs(docdir + 'pycom.doc')              # save in doc file
newdoc.SaveAs(docdir + 'copy.doc')
newdoc.Close( )

# open and change a doc file
olddoc = word.Documents.Open(docdir + 'copy.doc')
finder = word.Selection.Find
finder.text = 'COM'
finder.Execute( )
word.Selection.TypeText('Automation')
olddoc.Close( )




I need to install win32com.client library and test it first, then I may try VB.NET. Do you have any suggestions?
Was This Post Helpful? 0
  • +
  • -

#13 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: MS word file and python

Posted 08 February 2011 - 09:54 AM

Same suggestion as before. Use VB.net for a GUI and I/O and Iron Python for the summarization. If that code works and you don't want to use VB.net, more power to you.

This post has been edited by atraub: 08 February 2011 - 09:55 AM

Was This Post Helpful? 0
  • +
  • -

#14 wisam abbasi  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 72
  • Joined: 12-December 09

Re: MS word file and python

Posted 08 February 2011 - 09:56 AM

View PostJackOfAllTrades, on 08 February 2011 - 09:46 AM, said:


Thanks alot, this link was really helpful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1