[Tutor] ascii encoding

Max Noel maxnoel_fr at yahoo.fr
Tue Jan 25 00:40:00 CET 2005


On Jan 24, 2005, at 23:29, Luis N wrote:

> How would I best turn this string:
>
> '2005-01-24 00:00:00.0'
>
> into this string:
>
> '2005%2D01%2D24%2000%3A00%3A00%2E0'
>
> In order to call a URL.
>
> I've hunted through the standard library, but nothing seemed to jump 
> out.

	The pathname2url in urllib seems to do what you want:

 >>> import urllib
 >>> urllib.pathname2url('2005-01-24 00:00:00.0')
'2005-01-24%2000%3A00%3A00.0'

	And urllib.url2pathname does the opposite conversion.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"



More information about the Tutor mailing list