Anyone ever overridden a builtin by accident?
Christopher Blunck
blunck at gst.com
Tue Sep 9 23:56:14 EDT 2003
Argh. Hate it when I do this....
On Sat, 06 Sep 2003 20:22:19 -0700, John Ladasky wrote:
> Hi there,
>
> Just wanted to share a frustrating programming bug that, when I
> figured it out, made me gasp, and then laugh.
>
> In one of my programs I wrote...
>
> c = max(a,b)
>
> ...and I was getting the most annoying, frustrating error message:
> "type 'int' is not callable."
>
> What the heck? I wasn't calling an integer, I was calling the
> __builtin__ function, max()!
>
> I dropped out of my regular editor (SciTE), opened IDLE, and tried
> typing in bits of my code, including the call to max(). Everything
> seemed to work fine.
>
> Then, I finally spotted the problem. At the beginning of my program I
> had defined a variable called "max"! I had overridden the __builtin__
> function by mistake.
>
> Is there ever a good reason to override something in __builtin__?
> It's powerful, but potentially quite confusing. Can the interpreter
> be instructed to give a warning message when you do it?
>
> Yes indeed, *everything* in Python is an object. Let the newbie
> beware!
>
> --
> John J. Ladasky Jr., Ph.D.
> Department of Biology
> Johns Hopkins University
> Baltimore MD 21218
> USA
> Earth
More information about the Python-list
mailing list