exception in min() of python

196 views
Skip to first unread message

saintthor

unread,
Jan 5, 2010, 2:12:16 AM1/5/10
to Google App Engine
code:

if x1 < min( x2, x3 ):

gets an exception: TypeError: 'int' object is not callable

x1,x2,x3 are floats.

change the code to:

if x1 < x2 and x1 < x3:

everything is OK.

Nickolas Daskalou

unread,
Jan 5, 2010, 2:25:25 AM1/5/10
to google-a...@googlegroups.com
I'm guessing you assigned min to an integer value beforehand, eg:

min = 123
....

if x1 < min( x2, x3 ):
....


2010/1/5 saintthor <sain...@gmail.com>

--

You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.



saintthor

unread,
Jan 6, 2010, 2:10:50 AM1/6/10
to Google App Engine
haha, you are right !!!!


On Jan 5, 3:25 pm, Nickolas Daskalou <n...@daskalou.com> wrote:
> I'm guessing you assigned min to an integer value beforehand, eg:
>
> min = 123
> ....
> if x1 < min( x2, x3 ):
> ....
>

> 2010/1/5 saintthor <saintt...@gmail.com>


>
> > code:
>
> > if x1 < min( x2, x3 ):
>
> > gets an exception: TypeError: 'int' object is not callable
>
> > x1,x2,x3 are floats.
>
> > change the code to:
>
> > if x1 < x2 and x1 < x3:
>
> > everything is OK.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Google App Engine" group.
> > To post to this group, send email to google-a...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > google-appengi...@googlegroups.com<google-appengine%2Bunsu...@googlegroups.com>

Wesley C (Google)

unread,
Jan 6, 2010, 9:44:37 PM1/6/10
to google-a...@googlegroups.com
yep, this behavior is "allowed" because in Python, "min" is not a
reserved word. unfortunately, this (lack of) restriction easily causes
users to overwrite existing data and methods that are popular variable
names.

for future reference, aside from min, other well-known Python
built-ins that are inadvertently used as variables include: len, str,
list, dict, file, max, hash, type, object, set, id, dir, and buffer.

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wesc...@google.com
developer relations :: google app engine


On Tue, Jan 5, 2010 at 11:10 PM, saintthor <sain...@gmail.com> wrote:
> haha,  you are right !!!!
>
>
> On Jan 5, 3:25 pm, Nickolas Daskalou <n...@daskalou.com> wrote:
>> I'm guessing you assigned min to an integer value beforehand, eg:
>>
>> min = 123
>> ....
>> if x1 < min( x2, x3 ):
>> ....
>>
>> 2010/1/5 saintthor <saintt...@gmail.com>

Gabriel Robertson

unread,
Jan 6, 2010, 10:06:53 PM1/6/10
to google-a...@googlegroups.com
On Wed, Jan 6, 2010 at 7:44 PM, Wesley C (Google) <wesc...@google.com> wrote:
> yep, this behavior is "allowed" because in Python, "min" is not a
> reserved word. unfortunately, this (lack of) restriction easily causes
> users to overwrite existing data and methods that are popular variable
> names.
>
> for future reference, aside from min, other well-known Python
> built-ins that are inadvertently used as variables include: len, str,
> list, dict, file, max, hash, type, object, set, id, dir, and buffer.

You can get a list of all built in names by __builtins__.
__builtins__ is a python list of string of everything that is at the
builtin (global) scope.

G

unread,
Jan 7, 2010, 2:42:58 PM1/7/10
to Google App Engine
Even better; use pylint or pychecker on source code and receive
automated "then don't lift your elbow like that" hints. :)

Redefining built-in 'min'
(min) shadows builtin

http://www.google.com/search?q=pylint+pychecker

--
G

Reply all
Reply to author
Forward
0 new messages