newb question on strings

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Jun 25 09:27:52 CEST 2008


Dan Bishop a écrit :
> On Jun 24, 4:04 pm, "shand... at gmail.com" <shand... at gmail.com> wrote:
>> Are you trying to escape for a regular expression?
>>
>> Just do re.escape().
>>
>>>>> print re.escape('Happy')
>> Happy
>>>>> print re.escape("Frank's Diner")
>> Frank\'s\ Diner
>>
>> If you're escaping for URLs, there's urllib2.quote(), for a command
>> line, use subprocess.list2cmdline.
> 
> And if you're escaping for string literals in Python (or C and its
> descendants), you can do:
> 
>>>> print "Frank's Diner".encode('string-escape')
> Frank\'s Diner
> 

And finally, if you're escaping it to use it for a SQL query, any DB-API 
compliant adapter will automatically escape it's params if used correctly.



More information about the Python-list mailing list