[Tutor] Finding and replacing a space in a string.

Brian Connelly brian at connellyman.com
Wed Jan 28 16:36:59 EST 2004


Hey guys and gals...

I'm working with the csv module...I have a row[1] which is a ID.
let's call  ID = row[1].

My problem is that row[1] or ID is  6 characters or less and in some casses it has a '  '  space which i need to replace with a '-' and if  it does not have a space I would like to leave it alone.

Any sugestions ?

for example:

>>> id
'ZURE A'

newid  should become 'ZURE-A'

and if  id = 'WHITO'  newid = 'WHITO'


Thanks for the help :)
BCC
Learning python and loving it !






More information about the Tutor mailing list