urlencoding dictionaries

Andrew Dalke dalke at acm.org
Wed May 31 12:32:38 EDT 2000


Marc Tardif wrote:
>>>> params = {'one': 'First param',
>...           'two': None
>...          }
>>>> print urllib.urlencode(params)
>one=First+param&two=None
>
>Problem is, isn't "None" suppose to be a null object making it absurd to
>output "two=None"? Shouldn't urlencode output "two=" or nothing at all
>even? Is this a potential improvement upon the urllib module or is there a
>way to circumvent this problem I seem to be having?


If it had "two=" then how do you distinguish None from the empty string "",
which will also make a "two="?

The urllib doesn't store type information, it only stores their text
representation.  Simiarly, there's no way to distinguish between the
number 1 and the string 1.

You'll need to develop your own encoding scheme on top of what urllib
provides.

                    Andrew
                    dalke at acm.org







More information about the Python-list mailing list