Inspecting And Changing Strings In Python

Duncan Booth duncan.booth at invalid.invalid
Wed Apr 29 10:49:10 EDT 2009


"Jim Carlock" <jcarlock at MUNGED.microcosmotalk.com> wrote:

> Anyone here able to provide a link to the Python functions for
> comparing strings and updating strings? I'm looking to do some
> character by character analysis until I find the '@' character
> and then change the rest of the string after that.
> 
You cannot update a string: you must just build a new string with whatever 
content you require.

Something like (assuming your input is in the variable 'input':

def process(input):
  prefix, suffix = input.split('@')
  do_analysis(prefix)
  return prefix + '@' + create_new_suffix(suffix)

Have you been through the tutorial? 
http://www.python.org/doc/current/tutorial/index.html


-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list