Writting to file from file and printing using python

Simon Brunning simon at brunningonline.net
Fri Jul 28 05:14:35 EDT 2006


On 7/28/06, atanas Cosmas Nkelame <atanasy at gmail.com> wrote:
> Hi,
> I have  a task to write a program that will do the following.
>
> 1. Run from the command line

Check out the optparse module for this.

<http://docs.python.org/lib/module-optparse.html>

> 2. Get data from a text file (say data.txt) in the following format
>
>   111:      peter                  edward          peter at yahoo.com
>   112:      John                  sykes            john at yahoo.com
>   113:     edward                mutaga         edward at yahoo.com

Read the text file as normal, and use split to seperate the fields.

<http://tinyurl.com/8w8vo>

<http://docs.python.org/lib/string-methods.html>

> 3. Write that data in a prepared word document (which is essentially a
> letter)
>
> 4. Print the letters for the listed people (111,112,113) on a printer.

Word can be driven via COM, so this should be easy enough. See
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/279003> for a
simple example. To find out what you'll need to do, the simplest thing
might be to record a Word macro, and look at the VBA code that it
generates for you. You can convert this to Python and generalise the
bits you need to.

There, that's a starting point. Let us know what you come up with!
Give us a shout if you have any problems.

-- 
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list