So far i've got this and it returns something like:

-2087276233

import binascii
def getCRC(filename):
     filedata = open(filename).read()
     return binascii.crc32(filedata)

Someone told me that I had to use struct.pack or struct.unpack to change it to hex values.

I am not sure which type to convert to and would like some explanation to understand fully instead of coding in blind.

The final result should show the same CRC32 value as if you packed the file in WinRAR, checked it with the numerous SFV-checkers or whatever.

A link just in case:
http://docs.python.org/library/struct.html

Thanks alot in advance!

Post your code! Check your variables are properly set signed/unsigned!

import binascii
def getCRC(filename):
     filedata = open(filename).read()
     return binascii.crc32(filedata)

You may want to try a binary file read.

Can you define this method? I am not sure I understand what you mean.

I instead used a crc32.c script for use with subprocess .. Faster, and easier ..

Can you define this method? I am not sure I understand what you mean.

Binary read is simply opening the file under the mode 'read' plus 'binary'. Read up on the built-in open method here, and the answer will reveal itself.

I have tried both open(filename, 'r') and open(filename, 'rb')

I can get the file loaded into a string and then try
print binascii.crc32(file-in-string)

Still just gives me negative integers, what I want is the 8-char hexvalue.

I have tried both open(filename, 'r') and open(filename, 'rb')

I can get the file loaded into a string and then try
print binascii.crc32(file-in-string)

Still just gives me negative integers, what I want is the 8-char hexvalue.

Use 'rb', and RTFM

Use string formatting to print the hex value, just as the example in the docs shows you.

This article has been dead for over six months. Start a new discussion instead.