[Tutor] how to use replace() from a list

Norman Khine norman at khine.net
Sat Jun 16 19:39:29 CEST 2007



Hi I have this class:

def title_to_name(title):
    title = title.encode('ascii', 'replace')
    name = title.lower().replace('/', '_').replace('?',
'_').replace('.', '')
    return '_'.join(name.split())

Is there a way to have just one replace and so that:

replace('/', '_').replace('?', '_').replace('.', '_')

if I put these strings in a list

remove = ['/', '.', '?']

I get this error:

AttributeError: 'list' object has no attribute 'replace'

Thanks

Norman



More information about the Tutor mailing list