[Tutor] python string __add__
Tom Jenkins
tjenkins@devis.com
Fri Jun 6 08:52:02 2003
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