[PD][ot] py: converting tuple to list

david golightly davigoli at gmail.com
Sun Apr 2 22:43:28 CEST 2006


(moving to off-topic)

Since tuples are static after creation & can't be changed but only
reassigned, what you have to do is iterate over the items in the tuple
to create a new list:

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

return largs

I don't understand why you're trying to use reduce().  This method is
designed to call a function recursively over a set of items or over a
range, so that each subsequent iteration is called with the result of
the previous iteration.

Hopefully this is closer to what you're looking for.

-david

On 4/2/06, patco <megalegoland at yahoo.fr> 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.
>
> I need this script for fixing a problem with OSCx,
>  which doesn't allow spaces in sent messages.
>
> Thank in advance for any coment.
>
> Patco.
>
>
>
>
>
>
>
>
> ___________________________________________________________________________
> Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.
> Téléchargez sur http://fr.messenger.yahoo.com
>
> _______________________________________________
> PD-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
>




More information about the Pd-list mailing list