Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 21st, 2003, 02:49 PM
kashifkhan kashifkhan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 kashifkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 22 sec
Reputation Power: 0
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"

Reply With Quote
  #2  
Old August 21st, 2003, 03:11 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,430 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 41 m 55 sec
Reputation Power: 784
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

Reply With Quote
  #3  
Old August 21st, 2003, 03:30 PM
kashifkhan kashifkhan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 kashifkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 22 sec
Reputation Power: 0
kewl. but where do i download it from?

Reply With Quote
  #4  
Old August 21st, 2003, 03:32 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,430 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 41 m 55 sec
Reputation Power: 784
The zlib module comes along with my python installation (RedHat Linux 7.1).

Reply With Quote
  #5  
Old August 21st, 2003, 03:35 PM
kashifkhan kashifkhan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 kashifkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 22 sec
Reputation Power: 0
im on windows. and when i did crc32(c) it gave me an error. Does it come with XP as well?

Reply With Quote
  #6  
Old August 21st, 2003, 03:38 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,430 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 41 m 55 sec
Reputation Power: 784
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')

Reply With Quote
  #7  
Old August 21st, 2003, 03:49 PM
kashifkhan kashifkhan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 kashifkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 22 sec
Reputation Power: 0
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

Reply With Quote
  #8  
Old August 21st, 2003, 05:31 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #9  
Old August 21st, 2003, 05:55 PM
kashifkhan kashifkhan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 kashifkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 22 sec
Reputation Power: 0
thanks, that worked. How do i declare an int as a long int in python?

Reply With Quote
  #10  
Old August 21st, 2003, 07:00 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
You do it the same way as you do an int just using a long number instead pretty simple i.e long = 10000000000

Mark.

Reply With Quote
  #11  
Old August 21st, 2003, 07:58 PM
kashifkhan kashifkhan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 kashifkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 22 sec
Reputation Power: 0
oh kewl, so it automatically knows when its a long huh

no need to write
long int k =whatever number
???

Reply With Quote
  #12  
Old August 21st, 2003, 10:45 PM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 7 m 43 sec
Reputation Power: 6
Send a message via ICQ to SolarBear Send a message via MSN to SolarBear
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.

Reply With Quote
  #13  
Old August 22nd, 2003, 08:16 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #14  
Old August 22nd, 2003, 08:44 AM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Where would it be useful to "declare" the number to be a long within the range of pure Python?

Reply With Quote
  #15  
Old August 22nd, 2003, 08:55 AM
<