[PD] py: converting tuple to list

sven ml.sven at subscience.de
Sun Apr 2 22:55:55 CEST 2006


At 21:29 02.04.2006, patco wrote:
>Hello,
>
>   May be you could be in some help with a script I am trying to do
>  for replacing spaces in a string.
>
>I've tried this:
>
>def space2_(*args):
>       """replaces space with _"""
>       return  reduce(args.replace(' ','_'), args)
>
>and the console is returning this error:
>
>AttributeError: 'tuple' object has no attribute 'replace'
>
>  With a very limited knowledge of python, I am having pain for finding
>how to transform (*args) into [*args] or anything that would allow
>the fonction 'replace' to work.

replace only works for strings. there's no replace for lists and tuples.
if your *args tuple contains just strings you could convert them all like that:

args = list(args)
for i in range(len(args)): args[i] = args[i].replace(' ', '_')
return args

forget "reduce", it will be gone in py3 anyway.

sven. 





More information about the Pd-list mailing list