[Baypiggies] Input in hex format

David Elsen elsen.david08 at gmail.com
Fri Aug 15 00:45:17 CEST 2008


Thanks Chris.

I tried following:
#reg_offset = int(raw_input("enter offset",16))
reg_offset = int("enter offset",16)
print reg_offset

and got the following error with "raw input" option:

Traceback (most recent call last):
  File "testclass.py", line 33, in <module>
    reg_offset = int(raw_input("enter offset",16))
TypeError: [raw_]input expected at most 1 arguments, got 2
Without raw input, I got following error:

Traceback (most recent call last):
  File "testclass.py", line 34, in <module>
    reg_offset = int("enter offset",16)
ValueError: invalid literal for int() with base 16: 'enter offset'


I want to use it in a class like following:

class Reg:
        def __init__(self, name, offset, val):
                self.name = name
                self.offset = offset
                self.val = val


*reg1 = Reg("Address Register", 0, 50000000)*
**
*Here the offset and val fields are in HEX which I want to pass them to my
class REG.*

print 'reg name = %s'%reg1.name
print 'reg offset =%x'%reg1.offset
print 'reg reset val =%d'%reg1.val

Thanks,
David
On Thu, Aug 14, 2008 at 2:30 PM, Chris Rebert <cvrebert at gmail.com> wrote:

> hex_num = int(raw_input("prompt here"), 16) #allows optional leading 0X or
> 0x
> binary_num = int(raw_input("prompt here"),2)
>
> Or generally:
> num = int("number as string", base)
>
> - Chris
>
> ========
> Follow the path of the Iguana...
> Rebertia: http://rebertia.com
> Blog: http://blog.rebertia.com
>
>
> On Thu, Aug 14, 2008 at 2:23 PM, David Elsen <elsen.david08 at gmail.com>
> wrote:
> >
> > Greetings all,
> >
> > One very simple question please.
> >
> > I want to assign hex value to one of my class field.
> >
> > Can someone please tell me how can give hex and binary input to one of my
> > class field?
> >
> > By default, it is taking in decimal and that is expected. After all code
> > should be for human not for machines.
> >
> > thanks,
> > david
> > _______________________________________________
> > Baypiggies mailing list
> > Baypiggies at python.org
> > To change your subscription options or unsubscribe:
> > http://mail.python.org/mailman/listinfo/baypiggies
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20080814/aacdd03c/attachment.htm>


More information about the Baypiggies mailing list