Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    21
    Rep 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"
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    21
    Rep Power
    0
    kewl. but where do i download it from?
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    The zlib module comes along with my python installation (RedHat Linux 7.1).
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    21
    Rep Power
    0
    im on windows. and when i did crc32(c) it gave me an error. Does it come with XP as well?
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    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')
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    21
    Rep 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
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    21
    Rep Power
    0
    thanks, that worked. How do i declare an int as a long int in python?
  18. #10
  19. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You do it the same way as you do an int just using a long number instead pretty simple i.e long = 10000000000

    Mark.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    21
    Rep Power
    0
    oh kewl, so it automatically knows when its a long huh

    no need to write
    long int k =whatever number
    ???
  22. #12
  23. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    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.
  24. #13
  25. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    you might wana look at http://www.python.org/doc/current/li...snumeric.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.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    12
    Where would it be useful to "declare" the number to be a long within the range of pure Python?
  28. #15
  29. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Sorry percivall, I dont follow .. english skills are a lil crap (even more imbarising is i'm british )

    Mark.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo