[Tutor] str format conversion help

eMyListsDDg emylistsddg at gmail.com
Thu Jul 15 05:08:45 CEST 2010


Steve,


glad you pointed that out. 

struct.unpack or something...i'll look into that module.

thx



> On 14-Jul-10 11:35, eMyListsDDg wrote:

>> '\x00\x11\xb2\x00@,O\xa4'


>> the above str is being returned from one key/value pair in a dictionary. it is the addr of a network device.


>> i want to store the addr's in their 8byte mac format like this,

>>      [00 11 b2 00 40 2C 4F A4]

>> the combinations of format strings using the print statement hasn't resulted in what i need.

> A few hints:

> Remember that the string is a set of raw binary values, so using ord() 
> on each character would give you the numbers you can then have 
> str.format() render as hex values.

> You might also find the struct module helpful.


>> looking for a suggestion on how to format this, '\x00\x11\xb2\x00@,O\xa4' into this [00-11-B2-00-40-2C-4F-A4]


>> tia

>> Best regards,
>>   eMyListsDDg                            mailto:eMyListsDDg at gmail.com

>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor

> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



-- 
Best regards,
 eMyListsDDg                            mailto:eMyListsDDg at gmail.com



More information about the Tutor mailing list