Why is Python so slow ?- revisited.

Bernhard Herzog herzog at online.de
Thu Jun 22 06:47:46 EDT 2000


hzhu at knowledgetrack.com (Huaiyu Zhu) writes:

> On Tue, 20 Jun 2000 01:30:19 GMT, William Dandreta
> <wjdandreta at worldnet.att.net> wrote: 
> 
> >
> >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.
> 
> 
> If you really want to replace an internal method in an imported module,
> maybe you can try this (not tested):
> 
> import string, strop
> string.joinfields = strop.joinfields
> string.splitfields = strop.splitfields
> from string import replace

Messing around with strop like that shouldn't be necessary. string.py
already imports all of strop at the end:

# Try importing optional built-in module "strop" -- if it exists,
# it redefines some string operations that are 100-1000 times faster.
# It also defines values for whitespace, lowercase and uppercase
# that match <ctype.h>'s definitions.

try:
	from strop import *
	letters = lowercase + uppercase
except ImportError:
	pass # Use the original, slow versions


-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list