Coding issue with XML for word document

Pavol_Lisy at f38.n261.z1 Pavol_Lisy at f38.n261.z1
Tue Feb 7 18:04:32 EST 2017


From: Pavol Lisy <pavol.lisy at gmail.com>

On 2/7/17, Steven D'Aprano <steve at pearwood.info> wrote:
> On Mon, 06 Feb 2017 17:00:25 -0800, accessnewbie wrote:
[...]
>> But when I try to bold, it bombs. It does not seem to like either of
>> these (+ myText + "<w:cr/>") (separately or together) appended on the
>> end.
>
> How are you trying to bold? If you're programming in a word processor,
> and you apply bold to your code, that won't work.
>
> What do you mean, "bombs"? Do you literally mean you are running a
> classic Macintosh from the 1990s and you are getting a fatal System Error
> in a "Bomb" dialog box?
>
> Otherwise, please be more precise: do you get a Blue Screen of Death? A
> kernel panic? Does the Python interpreter segfault? Or do you get an
> ordinary Python traceback?
>
> If it is an ordinary Python traceback, don't keep it a secret -- tell us
> what it says. COPY AND PASTE the traceback, in full, not just the last
> line.

I am afraid he means that it create mishmash in word document...

Dear accessnewbie I propose divide problem to smaller subproblems.

For example make python code as simple as possible (avoid python part if you
could! As Deborah wrote it is very probably not problem in python)

And try to explicitly try to write example text where is bold part.
#myBlurb = "<w:cr/><w:r><w:rPr><w:b/></w:rPr><w:t>My Favorite Cars -
</w:t></w:r><w:r><w:t> My favorite cars are available at </w:t></w:r>"
 + myText + "<w:cr/>"
myBlurb = "<w:cr/><w:r><w:rPr><w:b/></w:rPr><w:t>My Favorite Cars -
</w:t></w:r><w:r><w:t> My favorite cars are available at </w:t></w:r>
my garage <w:cr/>"

if it is still wrong try to make more and more similar text to: myBlurb =
"<w:cr/>My Favorite Cars - My favorite cars are available at my garage<w:cr/>"

I mean for example remove "<w:rPr><w:b/></w:rPr>" part etc.

Second - This is probably not your problem (unless you have special char in
your example myList) but if you could have xml spec chars in your input then
python could help. See example ->

>>> from xml.sax.saxutils import escape
>>> escape("< & >")
'< & >'

myBlurb = "<w:cr/>My Favorite Cars - My favorite cars are available at " +
escape(myText) + "<w:cr/>"  # this is safer than your code!

I hope you understand why it is useful. :)




More information about the Python-list mailing list