Coding issue with XML for word document

Steven D'Aprano steve at pearwood.info
Tue Feb 7 02:53:41 EST 2017


On Mon, 06 Feb 2017 17:00:25 -0800, accessnewbie wrote:

> I am constructing a sentence to insert into a word xml template. My code
> is below
>
> #Create a list
> if len(myList) > 0:
>     if len(myList) > 1:

What is myList? Where does it come from?


>         testText = list_format(myList) + " dealers."

What does list_format() do?


>     else:
>         myText = myList[0] + " dealer."


Why does one branch set the variable "testText" and the other branch set 
a different variable "myText"?



> #Contruct sentence
> 
>     #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/>My Favorite Cars - My favorite cars are available
>     at " + myText + "<w:cr/>"
> else:
>     myBlurb = ""




[...]
> This works
> 
> myBlurb = "<w:cr/>My Favorite Cars - My favorite cars are available at "
> + myText + "<w:cr/>"

As far as I can see, that is exactly the same as the line of code above.


> 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.

 
> Thia does not work
> 
> 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/>

You are missing a close quote at the very end:

#WRONG
"<w:cr/>


#RIGHT
"<w:cr/>"





-- 
Steve



More information about the Python-list mailing list