[Tutor] str format conversion help

2010-07-14 Thread eMyListsDDg

'\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.


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,
 eMyListsDDgmailto:emylists...@gmail.com

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] str format conversion help

2010-07-14 Thread eMyListsDDg
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,
>>   eMyListsDDgmailto:emylists...@gmail.com

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

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



-- 
Best regards,
 eMyListsDDgmailto:emylists...@gmail.com

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] str format conversion help

2010-07-14 Thread eMyListsDDg
Hello Alan,

> First please start new threads wirth a new email, do not reply to 

thought i did, my apologies.



> "eMyListsDDg"  wrote 

> First please start new threads wirth a new email, do not reply to 
> a previous post - it confuses threaded readers. (and sometimes 
> human readers too!)

>> '\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]

> Thats what you've got. The string is merely a representation 
> of that data.

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

> format strings are used to display data not to store it.
> Do you really want to display the data in the format you've 
> shown? Or do you really want to store it as 8 bytes?


the format shown. now that you point out a few things, it really wouldn't 
matter. 

> The two concepts are completely different and more 
> or less unrelated.

i see that now, as a newbie to python. 


>> 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]

> OK, to display it you need to extract each byte and convert it to 
> a string representing the hex value. Fortunately you an treat a 
> string of bytes as charactrers and the hex() function will give you 
> the hex representation. So...

> print "[%s]" % ('-'.join([hex(v) for v in theValue]) )

helps me to understand the concept differences you pointed out better

appreciate the help...


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] str format conversion help

2010-07-15 Thread eMyListsDDg
thanks,
   

def conv_tst(bytes)

 return ('-'.join([binascii.hexlify(v) for v in bytes]))



i ended up experimenting with the suggestions and the above returns what i'm 
looking for, i.e., the formatted mac addr to store in a sqlite db. 

i'm sure there are other ways, though the above is working now.



mucho gracias all




> use de fucntion encode. For example:

> '\x7e\x00\x20'.encode('hex') will return that = '7e0020'  


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] str format conversion help

2010-07-15 Thread eMyListsDDg

yep, i noticed. ;^)

no prob, through your help, it is working the way i needed.

thanks



>> print "[%s]" % ('-'.join([hex(v) for v in  theValue]) )

> Oops, that leaves 0x at the front of each byte.

> You could strip that off with

> print "[%s]" % ('-'.join([hex(v)[2:] for v in  theValue]) )

> Sorry,

> Alan G.



-- 
Best regards,
 eMyListsDDgmailto:emylists...@gmail.com

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] howto install a "curses" lib on win7

2017-10-27 Thread eMyListsDDg
on a win7 system with python ver=2.7.14,  a python script i'm trying to utilize 
returns : 

#-

Traceback (most recent call last):
  File "salamandra.py", line 16, in 
import curses
  File "c:\python27\lib\curses\__init__.py", line 15, in 
from _curses import *
ImportError: No module named _curses

#-


if this machine was running linux probably wouldn't be an issue, but on Win7 
how can i get a 'curses' lib installed so this script runs?

tia











___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] howto install a "curses" lib on win7

2017-10-28 Thread eMyListsDDg
i had found this one "curses-2.2-cp27-none-win_amd64.whl" at 
www.lfd.uci.edu/~gohlke/pythonlibs/#curses , used pip to install. earlier pip 
attempts failed, but that was me/user typo error i realized after your reply. 
got the syntax correct for pip and the .whl installed.

i put link above incase another user has same issue,

thanks for the help, the script runs and didn't need cygwin thankfully.

 






> On 28/10/17 06:10, eMyListsDDg wrote:


>> on Win7 how can i get a 'curses' lib installed so this script runs?

> Do a Google search for windows curses, there are at least
> a couple of options. I've no experience of how well they
> work however because...

> ...as a last resort, install cygwin and use the
> Python that comes with cygwin which includes a curses module
> that works with the cygwin bash terminal. But cygwin is big
> and probably a sledgehammer for your nut if all you want is
> curses.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor