Forgetting "()" when calling methods

Roy Smith roy at panix.com
Fri Apr 25 18:46:21 EDT 2003


Erik Max Francis <max at alcyone.com> 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.

Not to mention that clever use of __getattr__ can make almost anything 
do something useful.  Or, if not useful, at least unexpected :-)




More information about the Python-list mailing list