471,578 Members | 1,306 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,578 software developers and data experts.

convert string to the "escaped string"

Hi,
I am trying to convert string to the "escaped string".
example: from "0xf" I need "\0xf"
I am able to do it like:

a="0xf"
escaped_a=("\%s" % a ).decode("string_escape")

But it looks a little bit complicated in this beautiful language to me
.....

Regards

Petr Jakes

Nov 22 '05 #1
3 3209
small mistake in my previous posting, sorry!!!!
from "0xf" I need "\xf" of course
and mentioned code gives me "\0xf" of course.

Thanks for your postings

Petr Jakes

Nov 22 '05 #2
Petr Jakes wrote:
I am trying to convert string to the "escaped string".
example: from "0xf" I need "\0xf" I am able to do it like:

a="0xf"
escaped_a=("\%s" % a ).decode("string_escape")

But it looks a little bit complicated in this beautiful language to me


I suspect that optimizing for people who want to turn "0xf" into
chr(0) + "xf" isn't exactly a priority...

if that's really what you want, of course. are you sure you didn't
mean to write, say

chr(int("0xf", 0))

(that is, convert 0xf to a character) or

repr(chr(int("0xf", 0)))

(that is, convert 0xf to a character, and convert that character to a
string literal)

?

</F>

Nov 22 '05 #3
Fredrik, thanks for your posting. I really appretiate your reply and
your way how you kindly answer even stupid newbie's questions on this
mailing list.
I was trying: int("0xf") but I did not have idea about the optional
"base" parameter for the int function.
Thanks a lot.
Petr

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by privetv7 | last post: by
2 posts views Thread by Joebloggs | last post: by
16 posts views Thread by ondekoza | last post: by
10 posts views Thread by =?Utf-8?B?RWxlbmE=?= | last post: by
5 posts views Thread by Just Another Victim of the Ambient Morality | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.