I'm using a modulu on a variable that has a hex numeric value, apparently I;m doing something wong:

import sys
import fileinput

if len(sys.argv) != 2:
        print 'Usage: ', sys.argv[0], 'val'
        sys.exit(1)

offset = sys.argv[1]

print 'offset=',offset

mod = offset%4096
if mod != 0:
        print "unaligned: ",offset

since I get:

python ~dan/project/scripts/xx 0x00000001
offset= 0x00000001
Traceback (most recent call last):
File "/home/dan/project/scripts/xx", line 13, in <module>
mod = offset%4096
TypeError: not all arguments converted during string formatting

help?

The list sys.argv contains only strings, not numerical values. So you must convert your argument with offset = int(sys.argv[1]) . Python thought you were using the string modulus operator, which has a completely different meaning.

commented: right on +10

The list sys.argv contains only strings, not numerical values. So you must convert your argument with offset = int(sys.argv[1]) . Python thought you were using the string modulus operator, which has a completely different meaning.

Right, int(offset,16) seems to do the trick.
Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.