1

I need to unpack information in python from a C Structure, doing it by the following code:

struct.unpack_from('>I', file.read(4))[0]

and afterwards, writing changed values back:

new_value = struct.pack('>I', 008200)
file.write(new_value)

a few examples: 008200 returns an syntaxerror: invalid token. 000010 is written into: 8 000017 is written into: 15 000017 returns a syntaxerror.

I have no idea what kind of conversion that is. Any kind of help would be great.

1 Answer 1

1

This is invalid python code and is not related to the struct module. In python, numbers starting with a zero are octal (base 8). So, python tries to decode 008200 in octal but '8' isn't valid. Assuming you wanted decimal, use 8200. If you wanted hex, use 0x8200.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.