overriding built-ins

Gerrit Holl gerrit at nl.linux.org
Sun Sep 28 16:29:47 EDT 2003


dan wrote:
> 1) Is it possible (without recompiling and changing the core Python
> behavior) to write functions that utilize the same syntax as built-in
> functions?  IE, can I create a function that does this:
> 
> >>>printCaps "hello"          #note no parentheses
> HELLO

No. This is not possible.

> 2) Is it possible to do this with the built-in keywords themselves, ie
> override functions such as print?

print is a statement, not a function. Builtin functions can be overwritten.
Statements cannot be overwritten. You can override functions like len, map,
etc. though, but it is not recommended.

Gerrit.

-- 
53. If any one be too lazy to keep his dam in proper condition, and
does not so keep it; if then the dam break and all the fields be flooded,
then shall he in whose dam the break occurred be sold for money, and the
money shall replace the corn which he has caused to be ruined.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list