Help newbie!

Chris Barker chrishbarker at attbi.com
Tue Dec 11 23:02:18 CET 2001


Johan Barelds wrote:
> >>> replace("hello","hel","hol")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> NameError: name 'replace' is not defined
> ========================================================================
> What do i have to do to get the command "replace" working?

you have two options:

1) it is a method of string objects:
>>> oldstring = "hello"
>>> newstring = oldstring.replace("hel","hol")
>>> newstring
'hollo'

2) is is in the string module:
>>> import string
>>> string.replace("hello","hel","hol")
'hollo'
>>>

Also, check out:
http://www.python.org/doc/current/tut/tut.html

and 
http://www.python.org/doc/Newbies.html

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at attbi.net                ---           ---           ---
                                     ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list