Python vs Visual Basic

Discussion in 'Python' started by Orange Free, Oct 13, 2003.

  1. Orange Free

    Orange Free Guest

    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.
     
    Orange Free, Oct 13, 2003
    #1
    1. Advertising

  2. 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
     
    Alex Martelli, Oct 13, 2003
    #2
    1. Advertising

  3. Orange Free

    Guest

    Alex Martelli wrote:
    >
    > Orange Free wrote:
    >
    > 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.


    I just looked at some RTF's, and they contain Ascii character 10's (\n)
    not paired with Ascii character 13's (\r). This is not a TEXT
    format file according to MS's OS's. If you try to write this data from
    Python as a text file, you'll get the \r's inserted automatically, the
    contents of the file will change, and who knows what will result.

    Still, the rtf format is a good one because other programs more
    affordable than MS Word do a reasonably good job of reading and
    writing it.

    Al
     
    , Oct 13, 2003
    #3
  4. Orange Free

    Terry Reedy Guest

    "Orange Free" <> wrote in message
    news:...
    > 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.


    Mark Hammond, who wrote the Windows extensions that include the COM
    tools, also wrote Python Programming on Win 32. Oreilly's page
    http://www.oreilly.com/catalog/pythonwin32/
    has a link to the following sample chapter
    http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html
    Chapter 12 Advanced Python and COM.

    Several c.l.py posts have given other examples of COM programming.

    TJR
     
    Terry Reedy, Oct 13, 2003
    #4
  5. On Mon, 13 Oct 2003 07:56:45 -0700, wrote:

    >Alex Martelli wrote:
    >>
    >> Orange Free wrote:
    >>
    >> 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.

    >
    >I just looked at some RTF's, and they contain Ascii character 10's (\n)
    >not paired with Ascii character 13's (\r). This is not a TEXT
    >format file according to MS's OS's. If you try to write this data from
    >Python as a text file, you'll get the \r's inserted automatically, the
    >contents of the file will change, and who knows what will result.


    I just looked at an RTF file generated by MS Word. It had standard
    MS-DOS line ends.

    I believe that RTF doesn't much care which line-end convention you
    use. RTF is meant to be a platform independent interchange file, so I
    suspect programs importing them are expected to handle all common
    conventions and the programs creating them probably use whatever line
    end convention is normal on that platform.

    Line ends are actually mostly irrelevant in RTF files. Paragraph
    breaks, for instance, are specified by the '\par' RTF command. Even if
    you put a line break in the middle of a text word, it doesn't seem to
    break the word up once imported into Word.

    I believe the line end counts as whitespace where RTF requires
    whitespace, but that is its only significance. Other than that it is
    ignored. Though I haven't double checked, so don't sue me if there are
    some cases where that isn't true.

    Certainly in the context of Alex Martellis suggestion, the "what will
    result" is basically no problems whatsoever. Well, OK, I suppose the
    file size will get a few bytes shorter ;-)


    --
    Steve Horne

    steve at ninereeds dot fsnet dot co dot uk
     
    Stephen Horne, Oct 13, 2003
    #5
  6. Orange Free

    Dave Kuhlman Guest

    <posted & mailed>

    Alex Martelli wrote:

    > 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


    [snip]
    >
    > 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.


    I've read that the latest version of MS Word (or MS Office?) heavily
    uses XML. If that's true, perahps you should consider generating
    foo.xml that follows the MS Word XML document definition (again, if
    there is such a thing).

    Here is a quote from Tim Bray:

    <quote>When asked how XML-enabling will make a difference in MS
    Office, Bray quickly zeroes in on what in his view is the key
    differentiator in an XML-enabled Office suite vs the current one.
    "The important thing," he explains, "is that Word and Excel (and of
    course the new XDocs thing) can export their data as XML without
    information loss. It seems Word can also edit arbitrary XML
    languages under the control of an XML Schema, but I'm actually more
    excited by the notion of Word files also being XML files."</quote>

    And here is a link to the complete article:

    http://www3.sys-con.com/xml/rotate.cfm

    [snip]

    Dave

    --
    Dave Kuhlman
    http://www.rexx.com/~dkuhlman
     
    Dave Kuhlman, Oct 13, 2003
    #6
  7. Orange Free

    Guest

    Stephen Horne wrote:
    >
    > Certainly in the context of Alex Martellis suggestion, the "what will
    > result" is basically no problems whatsoever. Well, OK, I suppose the
    > file size will get a few bytes shorter ;-)
    >


    That's good. I've seen some RTF's that end with a binary 0 byte.
    That's not text either, but the RTF's I looked at today, probably
    created by Abiword or Open Office, don't have it.

    Can't RTF's contain arbitrary binary data embedded within (eg images)?


    Al
     
    , Oct 13, 2003
    #7

  8. > Can't RTF's contain arbitrary binary data embedded within (eg images)?
    >

    From the RTF specification:

    Pictures
    An RTF file can include pictures created with other applications. These
    pictures can be in hexadecimal (the default) or binary format.
     
    Rudy Schockaert, Oct 13, 2003
    #8
  9. Dave Kuhlman wrote:
    ...
    >>> questions and then generate a Microsoft Word document whose

    ...
    >> May I suggest an alternative? Perhaps you might be satisfied with
    >> generating a foo.rtf rather than foo.doc file. Now, the RTF

    ...
    > I've read that the latest version of MS Word (or MS Office?) heavily
    > uses XML. If that's true, perahps you should consider generating
    > foo.xml that follows the MS Word XML document definition (again, if


    If it's OK to generate a MS Word document file that's only readable
    by Windows/XP or however they call their latest version, Dave is most
    probably right. In most cases in which I've been asked to generate
    Office files, compatibility to previous releases (generally back to
    Office'97) was a requirement, expressed or implied (many non-techies don't
    realize this requirement isn't _automatically_ satisfied...) so I tend to
    assume it -- sorry, I should have made it explicit (but then so should the
    OP have, so we're even:).


    Alex
     
    Alex Martelli, Oct 13, 2003
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M P
    Replies:
    6
    Views:
    566
    Joe Fallon
    Aug 7, 2004
  2. Stewart
    Replies:
    1
    Views:
    545
    Ken Cox [Microsoft MVP]
    Feb 24, 2006
  3. Anthony Moss

    visual basic from visual C++

    Anthony Moss, Dec 16, 2003, in forum: C++
    Replies:
    1
    Views:
    300
    Aggro
    Dec 16, 2003
  4. Engineer
    Replies:
    6
    Views:
    671
    Jeremy Bowers
    May 1, 2005
  5. hunkgym
    Replies:
    1
    Views:
    2,024
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Oct 30, 2006
Loading...

Share This Page