Forgetting "()" when calling methods

A. Lloyd Flanagan alloydflanagan at
Wed Apr 30 16:53:26 CEST 2003

Roy Smith <roy at> wrote in message news:<roy-D5BE38.18462125042003 at>...
> Erik Max Francis <max at> wrote:
> > One thing that PyChecker, at least, is more likely to catch is "code has
> > no effect" statements like
> > 
> > 	sys.exit
> > 
> > Without the parentheses, this clearly can't do anything useful
> In a language as dynamic as Python, you have to be really careful with 
> words like "clearly".
> Invoking the name of an object to see if you raise a NameError could be 
> useful in some situations.  Within the past week or so, there was a 
> serious discussion on this group where code along the lines of:
>    try:
>       True
>    except NameError:
>       do stuff
> was suggested as a way to tell if the version of Python being run had 
> boolean support.

Just an FYI:  pychecker does indeed flag code like that as having 'no
effect', including the boolean test.  Very useful if you call a
function as a statement and forget the parentheses, easy to ignore if
you meant to do it.

More information about the Python-list mailing list