How do I convert a string into a string of bytes in python 2.7 -
i'm trying convert string coming raw_input() "string of bytes". when type variable manually (in code) works fine, returns me length of 5. however, when try enter "string of bytes" raw_input() returns me length of 20.
>>> x='\xb2\xb2\xb3\xb4\x01' >>> len(x) 5 >>> x=raw_input() \xb2\xb2\xb3\xb4\x01 >>> len(x) 20 i know why happening , how can fix it. in advance.
when submit string "\xb2\xb2\xb3\xb4\x01" raw_input() automatically escapes \ characters because thinks mean enter them part of string. results in representation of string read this:
in [2]: x=raw_input() \xb2\xb2\xb3\xb4\x01 in [3]: x out[3]: '\\xb2\\xb2\\xb3\\xb4\\x01' in [4]: print x \xb2\xb2\xb3\xb4\x01 unfortunately answer question shouldn't manually entering string of bytes raw_input().
Comments
Post a Comment