C Nielsen C Nielsen - 11 months ago 86
Python Question

Python Trailing L Problem

I'm using Python to script some operations on specific locations in memory (32 bit addresses) in an embedded system.

When I'm converting these addresses to and from strings, integers and hex values a trailing L seems to appear. This can be a real pain, for example the following seemingly harmless code won't work:


Or this:


Does anyone know how to avoid this?

So far I've come up with this method to strip the trailing L off of a string, but it doesn't seem very elegant:

if longNum[-1] == "L":
longNum = longNum[:-1]

Answer Source

If you do the conversion to hex using

 "%x" % 4220963601

there will be neither the 0x nor the trailing L.