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. Advertisements

  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. Advertisements

  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. Advertisements

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. =?Utf-8?B?SmFtZXNT?=

    ASP.NET Worker Process Thread Counts

    =?Utf-8?B?SmFtZXNT?=, Apr 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    857
    =?Utf-8?B?SmFtZXNT?=
    Apr 27, 2005
  2. R
    Replies:
    7
    Views:
    1,138
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=
    Jan 17, 2005
  3. utab
    Replies:
    3
    Views:
    291
    Victor Bazarov
    Feb 17, 2006
  4. Steven D'Aprano

    Re: function that counts...

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

    Re: function that counts...

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

    Re: function that counts...

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

    Re: function that counts...

    Jean-Michel Pichavant, May 24, 2010, in forum: Python
    Replies:
    7
    Views:
    455
    Bryan
    Jun 11, 2010
  8. Travis Griggs

    Fun with function argument counts

    Travis Griggs, Feb 12, 2014, in forum: Python
    Replies:
    0
    Views:
    131
    Travis Griggs
    Feb 12, 2014
Loading...