automating Outlook [repost]

Paul Boddie paul at boddie.net
Fri Aug 30 12:57:55 CEST 2002


paul at boddie.net (Paul Boddie) wrote in message news:<23891c90.0208290104.2aeccad9 at posting.google.com>...
> 
> [outlook.pyw]

For those of us in "international" environments, it might be nicer to
be able to use more than the basic 26 letters of the Latin alphabet
(not to mention accented characters and all the other alphabets). Here
are some interesting amendments to the script:

    #fh = open(tmp, "w")
    fh = open(tmp, "wb")
    #fh.write(body.encode('ascii', 'ignore').replace('\r\n', '\n'))
    fh.write(body.encode('utf-8', 'ignore').replace('\r\n', '\n'))

This writes the Unicode text out as UTF-8-encoded bytes, and we want
to make sure that all the information gets out - not just the bottom 7
bits.

If you're using gvim, it's possible to force the application to
recognise the encoding:

    #ed = r"c:\progra~1\vim\vim60\gvim.exe"	# *vi*  editor binary
    ed = r"c:\progra~1\vim\vim60\gvim.exe"
    arg1 = r'--cmd "set encoding=utf-8"'
    #spawnv(P_WAIT, ed, [ed, tmp])
    spawnv(P_WAIT, ed, [ed, arg1, tmp])

Here, we've added an extra argument which appears to do the trick.

Finally, we need to read in that UTF-8 text:

    #fh = open(tmp, "r")
    fh = open(tmp, "rb")
    #body = fh.read().replace('\n', '\r\n')
    body = unicode(fh.read(), "utf-8").replace('\n', '\r\n')

And now I can really be productive. Well, more productive than before,
anyway.

Paul



More information about the Python-list mailing list