.join() question

Discussion in 'Python' started by drs, Jul 9, 2003.

  1. drs

    drs Guest

    why does

    >>> ''.join(lst)


    not automatically do

    >>> ''.join([str(i) for i in lst])


    ? That is, is there ever a time when one does not want .join to make
    everything into a string? This seems like reasonable default behavior, but
    maybe I'm missing something?

    -doug
    drs, Jul 9, 2003
    #1
    1. Advertising

  2. drs

    Terry Reedy Guest

    "drs" <> wrote in message
    news:eo_Oa.14415$...
    > why does
    >
    > >>> ''.join(lst)

    >
    > not automatically do
    >
    > >>> ''.join([str(i) for i in lst])

    >
    > ? That is, is there ever a time when one does not want .join to

    make
    > everything into a string? This seems like reasonable default

    behavior, but
    > maybe I'm missing something?


    If the members of lst are already str strings, this would be a waste
    of time. If they are unicode strings, this would be the wrong thing
    to do. Auto conversions are not Python's style.

    Terry J. Reedy
    Terry Reedy, Jul 9, 2003
    #2
    1. Advertising

  3. drs

    drs Guest

    "Terry Reedy" <> wrote in message
    news:...
    >
    > "drs" <> wrote in message
    > news:eo_Oa.14415$...
    > > why does
    > >
    > > >>> ''.join(lst)

    > >
    > > not automatically do
    > >
    > > >>> ''.join([str(i) for i in lst])

    > >
    > > ? That is, is there ever a time when one does not want .join to

    > make
    > > everything into a string? This seems like reasonable default

    > behavior, but
    > > maybe I'm missing something?

    >
    > If the members of lst are already str strings, this would be a waste
    > of time. If they are unicode strings, this would be the wrong thing
    > to do. Auto conversions are not Python's style.


    >>> l = [u'abcde', 'fghij']
    >>> ''.join(l)

    u'abcdefghij'

    this seems to be auto converting the non-unicode to unicode?

    -d
    drs, Jul 9, 2003
    #3
  4. I would risk a guess that this comes under the "explicit is better than
    implicit" guideline.

    ''.join([str(i) for i in lst])

    Explains to everyone that you know the list has some non-string things,
    and you intend them to be str()'ified.

    Intention-guessingly yours,
    Simon.

    "drs" <> wrote in
    news:eo_Oa.14415$:

    > why does
    >
    >>>> ''.join(lst)

    >
    > not automatically do
    >
    >>>> ''.join([str(i) for i in lst])

    >
    > ? That is, is there ever a time when one does not want .join to make
    > everything into a string? This seems like reasonable default
    > behavior, but maybe I'm missing something?
    >
    > -doug
    >
    >
    >
    Simon Bayling, Jul 9, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXM=?=

    Table join question

    =?Utf-8?B?Q2hyaXM=?=, Mar 4, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    353
    =?Utf-8?B?Q2hyaXM=?=
    Mar 5, 2005
  2. Alan Silver
    Replies:
    0
    Views:
    864
    Alan Silver
    Jun 5, 2006
  3. googleboy
    Replies:
    1
    Views:
    902
    Benji York
    Oct 1, 2005
  4. EP
    Replies:
    7
    Views:
    375
    Peter Otten
    Mar 13, 2006
  5. nephish

    easy question about join method

    nephish, Aug 7, 2006, in forum: Python
    Replies:
    4
    Views:
    265
    nephish
    Aug 7, 2006
Loading...

Share This Page