Error using string.strip

Matt Gushee mgushee at havenrock.com
Sat Jan 8 10:39:29 EST 2000


Eric Hausig <codeslave at worldnet.att.net> writes:

> I'm very new to Python.  (In fact, I'm walking through the tuturial
> right now!)

Welcome!

> >>> string.strip('str') + 'ing'
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> NameError: string

This usually happens when you've forgotten an import statement. Just
do this first:

>>> import string

... and you should be fine. I think the concept you need to keep in
mind here is that Python is very modular. In other words, a great many 
commonly used functions/classes/methods are not built in but are in
the standard libraries. Most Python programs of any consequence make
generous use of 'import' statements.

Hope this helps.

-- 
Matt Gushee
Portland, Maine, USA
mgushee at havenrock.com
http://www.havenrock.com/



More information about the Python-list mailing list