May 2001
Intermediate to advanced
304 pages
6h 12m
English
(Obsolete) The strop is a low-level module that provides fast C
implementations of most functions in the string module. It is
automatically included by string, so there’s seldom any
need to access it directly.
However, one reason to use this module is if you need to tweak the path before you start loading Python modules. Example 13-5 demonstrates the module.
Example 13-5. Using the strop Module
File: strop-example-1.py
import strop
import sys
# assuming we have an executable named ".../executable", add a
# directory named ".../executable-extra" to the path
if strop.lower(sys.executable)[-4:] == ".exe":
extra = sys.executable[:-4] # windows
else:
extra = sys.executable
sys.path.insert(0, extra + "-extra")
import mymoduleIn Python 2.0 and later, you should use string methods instead of
strop. In Example 13-5, replace
“strop.lower(sys.executable)” with
“sys.executable.lower().”
Read now
Unlock full access