[Tutor] urllib
Jojo Mwebaze
jojo.mwebaze at gmail.com
Mon Dec 7 10:18:15 CET 2009
thanks, Senthil
On Mon, Dec 7, 2009 at 11:10 AM, Senthil Kumaran <orsenthil at gmail.com>wrote:
> On Mon, Dec 07, 2009 at 08:38:24AM +0100, Jojo Mwebaze wrote:
> > I need help on something very small...
> >
> > i am using urllib to write a query and what i want returned is
> 'FHI=128%2C128&
> > FLO=1%2C1'
> >
>
> The way to use urllib.encode is like this:
>
> >>> urllib.urlencode({"key":"value"})
> 'key=value'
> >>> urllib.urlencode({"key":"value","key2":"value2"})
> 'key2=value2&key=value'
>
> For your purpses, you need to construct the dict this way:
>
> >>> urllib.urlencode({"FHI":'128,128',"FHO":'1,1'})
> 'FHO=1%2C1&FHI=128%2C128'
> >>>
>
>
> And if you are to use variables, one way to do it would be:
>
> >>> x1,y1,x2,y2 = 1,1,128,128
> >>> fhi = str(x2) + ',' + str(y2)
> >>> fho = str(x1) + ',' + str(y1)
> >>> urllib.urlencode({"FHI":fhi,"FHO":fho})
> 'FHO=1%2C1&FHI=128%2C128'
>
> --
> Senthil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091207/e6f1686f/attachment.htm>
More information about the Tutor
mailing list