Re: function that counts...

Discussion in 'Python' started by Jerry Hill, May 19, 2010.

  1. Jerry Hill

    Jerry Hill Guest

    On Wed, May 19, 2010 at 4:25 PM, superpollo <> wrote:
    > Jerry Hill ha scritto:
    >>        sumofdigits = sum(int(char) for char in str(testval))

    >
    > this line gives me this:
    >
    > TypeError: 'int' object is not callable
    >
    > is it some new feature in >2.5 ?


    No, sum() has been a builtin since Python 2.3. Based on your first
    post, you have probably shadowed the builtin "sum" function by
    assigning an integer to a variable named "sum".

    --
    Jerry
     
    Jerry Hill, May 19, 2010
    #1
    1. Advertising

  2. Am 19.05.2010 22:58, schrieb superpollo:
    >
    > In [277]: prttn(25, 10000)
    > Out[277]: 348
    >
    > In [278]: prttn2(25, 10000)
    > Out[278]: 348
    >
    > In [279]: prttn3(25, 10000)
    > Out[279]: 348
    >
    > ok, bye!


    Just because I was curios:

    necoro@Zakarumiy ~ % python -m timeit "import test; test.prttn(25,10000)"
    10 loops, best of 3: 108 msec per loop

    necoro@Zakarumiy ~ % python -m timeit "import test; test.prttn2(25,10000)"
    10 loops, best of 3: 157 msec per loop

    necoro@Zakarumiy ~ % python -m timeit "import test; test.prttn3(25,10000)"
    10 loops, best of 3: 137 msec per loop

    Note: This is probably not representative ... just a quick check to get
    a raw feeling.

    - René


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.14 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

    iEYEARECAAYFAkv0WMkACgkQ4UOg/zhYFuCmUgCfVubGZK+0jTcBHky4ZrbNTeio
    Q8wAnRX8Bbt3HF4ikKSphO+A7QmGD1dR
    =kGxY
    -----END PGP SIGNATURE-----
     
    René 'Necoro' Neumann, May 19, 2010
    #2
    1. Advertising

  3. On Wed, 19 May 2010 22:58:22 +0200, superpollo wrote:

    > In [266]: del(sum)



    del is a statement, not a function, so the brackets are pointless. This
    is like writing:

    x = (1)

    instead of

    x = 1

    `del sum` is all you need.



    --
    Steven
     
    Steven D'Aprano, May 19, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. utab
    Replies:
    3
    Views:
    239
    Victor Bazarov
    Feb 17, 2006
  2. Steven D'Aprano

    Re: function that counts...

    Steven D'Aprano, May 19, 2010, in forum: Python
    Replies:
    5
    Views:
    327
    Albert van der Horst
    May 21, 2010
  3. Peter Pearson

    Re: function that counts...

    Peter Pearson, May 20, 2010, in forum: Python
    Replies:
    3
    Views:
    255
    Bryan
    May 26, 2010
  4. Raymond Hettinger

    Re: function that counts...

    Raymond Hettinger, May 24, 2010, in forum: Python
    Replies:
    2
    Views:
    306
    Bryan
    May 26, 2010
  5. Jean-Michel Pichavant

    Re: function that counts...

    Jean-Michel Pichavant, May 24, 2010, in forum: Python
    Replies:
    7
    Views:
    309
    Bryan
    Jun 11, 2010
Loading...

Share This Page