string formatting quirk?

Discussion in 'Python' started by anuraguniyal@yahoo.com, May 20, 2005.

  1. Guest

    Hi,

    ''%([]) doesn't raise exception
    but
    ''%('') does

    Can anyone explain me why??

    rgds
    Anurag
     
    , May 20, 2005
    #1
    1. Advertising

  2. Peter Otten Guest

    wrote:

    > ''%([]) doesn't raise exception
    > but
    > ''%('') does
    >
    > Can anyone explain me why??


    That is a side-effect of duck-typing. The duck-type of an empty list is
    indistinguishable from that of an empty dictionary. Not testing the exact
    type here achieves consistency with the behaviour of custom dictionaries,
    e. g:

    >>> class List(list):

    .... def __getitem__(self, index):
    .... return list.__getitem__(self, int(index))
    ....
    >>> "%(0)s" % List([42])

    '42'
    >>> "%(1)s %(0)s" % List([42, 24])

    '24 42'
    >>> "" % List([])

    ''

    Peter
     
    Peter Otten, May 20, 2005
    #2
    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. Chris Morris

    Re: dtd and quirk mode

    Chris Morris, Jul 22, 2003, in forum: HTML
    Replies:
    0
    Views:
    397
    Chris Morris
    Jul 22, 2003
  2. Richard
    Replies:
    1
    Views:
    413
  3. Blinky the Shark

    Konqueror Quirk? Safari?

    Blinky the Shark, Feb 18, 2004, in forum: HTML
    Replies:
    9
    Views:
    451
    Blinky the Shark
    Feb 20, 2004
  4. Spartanicus

    IE6 quirk check

    Spartanicus, Jul 16, 2004, in forum: HTML
    Replies:
    2
    Views:
    447
    Spartanicus
    Jul 16, 2004
  5. David Graham

    quirk or standard mode

    David Graham, Dec 21, 2005, in forum: HTML
    Replies:
    2
    Views:
    767
    David Graham
    Dec 21, 2005
Loading...

Share This Page