0

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?

Edited by dbbd: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by dbbd
2

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.

Edited by Gribouillis: n/a

Votes + Comments
right on
1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.