|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
implement crc32 in pythonhi some one told me that python has a built in crc32 functio
hi some one told me that python has a built in crc32 function. I have created this little program that computes the fib of numbers.
Now what i want to do is print out the crc32 of c. How do i do it, which file do i have to include....n00b here so detailed explanation will be appreciated. Code:
a=0
b=1
c=0
count = 2
while count<=10000:
c=a+b
print b
a=b
b=c
count=count+1
print "done"
|
|
#2
|
||||
|
||||
|
You need the zlib module.
http://web.pydoc.org/1.5.2/zlib.html
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
kewl. but where do i download it from?
|
|
#4
|
||||
|
||||
|
The zlib module comes along with my python installation (RedHat Linux 7.1).
|
|
#5
|
|||
|
|||
|
im on windows. and when i did crc32(c) it gave me an error. Does it come with XP as well?
|
|
#6
|
||||
|
||||
|
Have you tried qualifying the function with the namespace (i.e. zlib.crc32, instead of crc32). The following code works for me:
Code:
import zlib
print zlib.crc32('mystring')
|
|
#7
|
|||
|
|||
|
aha, that worked. BUT it doesnt convert int, only strings, i want to convert that int into a crc32
this is the error i get Traceback (most recent call last): File "C:\Documents and Settings\Admin\Desktop\fib.py", line 11, in -toplevel- print zlib.crc32(c) TypeError: crc32() argument 1 must be string or read-only buffer, not int |
|
#8
|
||||
|
||||
|
You could convert your int's to strings using the built-in str(obj) function then pass this to crc32 i.e zlib.crc32(str(c))
.Mark. |
|
#9
|
|||
|
|||
|
thanks, that worked. How do i declare an int as a long int in python?
|
|
#10
|
||||
|
||||
|
You do it the same way as you do an int just using a long number instead
pretty simple i.e long = 10000000000Mark. |
|
#11
|
|||
|
|||
|
oh kewl, so it automatically knows when its a long huh
no need to write long int k =whatever number ??? |
|
#12
|
||||
|
||||
|
Bad, bad guy. Why do you ask for slyfx.com answers on other boards ?
![]() And no, Python has dynamic casting, so you don't have to declare types. The following would work in Python: Code:
i = 1 i = 'Hello!' Most languages would throw an error since they're not of the same type, but Python is a cool dude. ![]() However, if you need to declare longs, put an 'L' after your number. Code:
c = 0L Python will treat it as a long unless you typecast it again using str() or another built-in function. Last edited by SolarBear : August 21st, 2003 at 10:49 PM. |
|
#13
|
||||
|
||||
you might wana look at http://www.python.org/doc/current/l...esnumeric.html, never looked at this page in any detail before but it does have allot of info about the different numberic types.I've only used shot int's, not had a use for long's yet. I knew you could make short int's long using the built-in long() function and that if a number is too long to be an int it's automatically cast as a long, but the L things pretty handy ![]() Thanks, Mark. |
|
#14
|
|||
|
|||
|
Where would it be useful to "declare" the number to be a long within the range of pure Python?
|
|
#15
|
| < |