Python - decode('hex')
Ganesh Pal
ganesh1pal at gmail.com
Mon Feb 20 14:43:54 EST 2017
On Feb 21, 2017 12:17 AM, "Rhodri James" <rhodri at kynesim.co.uk> wrote:
On 20/02/17 17:55, Ganesh Pal wrote:
> 1. The only difference between both the programs the difference are just
> the below lines.
>
> newdata = '64000101057804'.decode('hex')
>
> and
>
> newdata = ""
> newdata = '64000101057804'
> newdata.decode('hex')
>
>
> What is happening here and how do I fix this in program 2 ? for my eyes
> there doesn't look any difference .
>
Python strings are immutable; methods like decode() create a brand new
string for you. What your program 2 version does is to name the string of
hex digits "newdata", decode it as hex into a new string and then throw
that new string away. Your program 1 version by contrast decodes the
string of digits as hex and then names is "newdata", throwing the original
string of digits away
Thanks for the reply James.
How can I make my program 2 look like program 1 , any hacks ? because I
get newdata value( as a hx return value Of type string )from a function.
Regards,
Ganesh
More information about the Python-list
mailing list