[Baypiggies] Input in hex format
spmcinerney at hotmail.com
Fri Aug 15 01:28:05 CEST 2008
The 16 is the second arg of (int,..16),
not the second arg of raw_input("prompt here")
Date: Thu, 14 Aug 2008 15:45:17 -0700From: elsen.david08 at gmail.comTo: cvrebert at gmail.comCC: baypiggies at python.orgSubject: Re: [Baypiggies] Input in hex format
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.nameprint 'reg offset =%x'%reg1.offsetprint 'reg reset val =%d'%reg1.val
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 0xbinary_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.comBlog: 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>
Got Game? Win Prizes in the Windows Live Hotmail Mobile Summer Games Trivia Contest
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Baypiggies