Python vs Visual Basic

Alex Martelli aleax at aleax.it
Mon Oct 13 10:17:11 EDT 2003


Orange Free wrote:

> I want to create a program that will ask a user a series of questions
> and then generate a Microsoft Word document whose content is dictated
> by the answers.  I am not a professional programmer, and I understand
> only a little about OO programming.  Should I
> 
> a) stick to -- *gasp* -- Visual Basic to accomplish my goal;
> 
> b) use Python, with which I am somewhat familiar, and which I would
> prefer to use; or
> 
> c) find another hobby because I am only going to end up hurting
> myself?
> 
> I am aware of the COM tools within Python, but I have not been able to
> find documentation that makes much sense.  Any pointers to good,
> basic-level documentation would be much appreciated.

I'm sure either language will be fine for the "asking questions"
part.  In either case the hard times come in order to generate the
word document -- if you want to drive Microsoft Word for the purpose,
which is marginally easier from VB but not so much as to matter,
you need to learn something about the MS Word object model, which
IS quite rich and complicated.

May I suggest an alternative?  Perhaps you might be satisfied with
generating a foo.rtf rather than foo.doc file.  Now, the RTF format
isn't much easier or better documented than the DOC format, but it
has the advantage that RTF format files are TEXT.  Thus, you could
prepare a "TEMPLATE" RTF file, using recognizable placeholders for
or around the parts of contents you may want to change; the
process of "generating the output" then becomes quite simple:
read the template RTF file, remove placeholders and contained
text around pieces you want to omit, substitute placeholders for
parts you need to substitute, remove all other placeholders only,
emit the resulting text, done.  There are many templating systems
you can find on the net for Python, but, really, doing your own
is no biggie either.


Alex





More information about the Python-list mailing list