Why is Python so slow ?- revisited.

Jeremy Hylton jeremy at beopen.com
Tue Jun 20 18:22:27 EDT 2000


"William Dandreta" <wjdandreta at worldnet.att.net> writes:

> My error was that I did the following:
> 
> from strop import joinfields, splitfields
> from string import replace
> 
> I erroneously assumed that replace would use the joinfields, splitfields
> from strop, but it really used the joinfields, splitfields from string which
> are very slow.
> 

This is an important lesson to learn!  In Python, assignment is just a
name binding operation.  The import statement will load a module,
provided it hasn't already been loaded, and then do one or more
assignments to local names.

The "from clinic import argument" version you used loads the clinic
module, looks up the name argument in that module, and binds the
object it finds to the name argument in the current namespace.  From
this point forward, the only way to change the binding for argument in
the current namespace is to explicitly change it in the current
namespace.  If you change the binding in the clinic module, e.g.
    clinic.argument = clinic.abuse
then future lookups of argument or abuse in the clinic module will
return the same object.  But existing references, like the one created
by from clinic import argument will still point to the old object.

Jeremy



More information about the Python-list mailing list