Backslash Escapes

F

Felipe O

Hi all,
Whenever I take any input (raw_input, of course!) or I read from a
file, etc., any backslashes get escaped automatically. Is there any
elegant way of parsing the backslashes as though they were written in
a python string. The best I have so far right now goes like this:

def parse_backslash_escapes(input_string):
parts = input_string.split("'''") # That's ' " " " ' without the spaces
'"""'.join(eval + p + '"""') for p in parts)

I'm not entirely convinced that it's safe on two accounts.
+ Is that eval statement safe? The input could be coming from an
unfriendly source.
+ Are there any obscure backslash escapes or other tricks I should be aware of?

I guess the alternative is to make a dictionary of all the escapes I
want to support, but that sounds tedious and error-prone.

Thanks,

Felipe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top