Help for Python newbie

Alan Gauld alan.gauld at bt.com
Tue Jun 12 09:06:06 EDT 2001


Bob Hibberdine wrote:
> I quote from the manual:
> 
> join (words[, sep])

>>> import string
>>> print string.join.__doc__
join(list [,sep]) -> string

    Return a string composed of the words in list, with
    intervening occurrences of sep.  The default separator is a
    single space.

    (joinfields and join are synonymous)

>>> print mystring.join.__doc__
S.join(sequence) -> string

Return a string which is the concatenation of the strings in the
sequence.  The separator between elements is S.
>>>

In other words you looked at the docs for the join function 
within the string module but used the join method of the 
string class. They are not the same.

Other posters showed how to do what you want with string methods. 
Here is how to use the string module:

>>> import string 	# if you haven't already!
>>> mylist = ['1','2','3']
>>> mystring = ''
>>> mystring = string.join(mylist,'\t')
>>> print mystring
1       2       3
>>>

HTH,

Alan G.



More information about the Python-list mailing list