[Tutor] python string __add__

Guillaume willblake@wanadoo.fr
Fri Jun 6 09:49:01 2003


I've got some times to run the prog
and strangely when I type
string.join(mylist,")
I've got a syntax error with the little ^ under the
second parenthesis.
I use Python 2.2, could u explain me why?
Thanx

-----Message d'origine-----
De : tutor-admin@python.org [mailto:tutor-admin@python.org]De la part de
Tom Jenkins
Envoyé : jeudi 5 juin 2003 21:11
À : tpc@csua.berkeley.edu; tutor@python.org
Objet : Re: [Tutor] python string __add__


On Thursday 05 June 2003 02:00 pm, tpc@csua.berkeley.edu wrote:
> I have a script that will take decimal numbers of any length as command
> line arguments and output the binary equivalent.  However, I am trying to
> output one long string with no spaces.  I attempted __add__ but got empty
> spaces.  Is there a way for python string __add__ to output binary digits
> with no spaces ?
>

python has the ability to create a string from a sequence separated by a
given
delimiter.  in earlier pythons that capability is in the string module;
later
python, the string object itself had the method.

so

>>> import string
>>> mylist = ['s', 'p', 'a', 'm']
>>> string.join(mylist, '')
'spam'
>>> ''.join(mylist)
'spam'
>>> ','.join(mylist)
's,p,a,m'
>>>

hopefully with this bit you should be able to get what you want...

Tom


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor