strange behaviour of colon within string

Dave Angel davea at
Mon Oct 19 17:13:34 CEST 2009

khany wrote:
> On 19 Oct, 14:44, StarWing <weasley... at> wrote:
>> On Oct 19, 9:15 pm, khany <sharif.k... at> wrote:
>>> On 19 Oct, 13:44, khany <sharif.k... at> wrote:
>>>> <snip>
>>>> however it fails to create the string UNLESS i remove the colon (:) in
>>>> the http section. i tried to substitute it with chr(58) but it errors
>>>> the same without showing why. does anyone know what i am doing wrong?
>>>> is this peculiar to googleapps?
>> <snip>
>>> )
>>> here is the code
>>> ======
>>>   xml = <?xml version="1.0" encoding="utf-8"?> \
>>>     <findItemsAdvancedRequest xmlns=ttp://
>>> search/v1/services"> \
>>>     <categoryId>%(category)i</categoryId> \
>>>     <keywords>%(searchtext)s</keywords> \
>>>     <paginationInput> \
>>>       <pageNumber>%(page)i</pageNumber> \
>>>       <entriesPerPage>10</entriesPerPage> \
>>>     </paginationInput> \
>>>     </findItemsAdvancedRequest>' % \
>>>     {'category':9834, 'searchtext':"bmw", 'page':1}
>>>   print xml
>>> ======
>>> if i run this, the page is blank (even the source) with no errors or
>>> anything. if i remove the colon from the string (after the http) it
>>> prints the string on the browser fine.
>>> HTH
>> you can use a tri-quote string or make sure all lines end with \:
>> <snip>
> StarWing,
> The triple String works a treat thanks. Not sure what the colon issue
> was though. Now im getting Unsupported verb errors but thats an ebay
> API issue i can work with.
> Thanks to all for your help
> khany
The original version worked fine in Python 2.6.2, once I combined the 
line that the email/listserver split for us.  I also don't know what the 
colon issue was;  I suspect some other change happened at the same time 
you changed the colon.

I also recommend the triple quote, for a few reasons.  It avoids the 
risk that you'll forget one of the trailing backquotes.  It avoids the 
risk of having an extra space after the backquote (most editors don't 
show the spaces, I insist on visible whitespace).  And it lets you make 
the resulting string readable in source form.

However, for long strings, I strongly recommend you not combine the 
string assignment with the % formatting logic.  So I'd use a couple of 
lines, something like:

     format_string = """This
my formatted
   string %(formatfield)
with some indentation preserved"""
   xml = format_string % (.....)

You should consider running the program locally, and redirect the output 
into a text file.  Then you can examine exactly what's being produced.  
Sometimes the browser adds its own surprises.  I don't know anything 
about the googleapps constraints.


More information about the Python-list mailing list