469,903 Members | 1,612 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

string formatting quirk?

Hi,

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

Can anyone explain me why??

rgds
Anurag

Jul 19 '05 #1
1 1113
an**********@yahoo.com 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

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Thomas Philips | last post: by
10 posts views Thread by Oliver S. | last post: by
20 posts views Thread by hagai26 | last post: by
5 posts views Thread by Andrew Connell | last post: by
4 posts views Thread by Dennis Myrén | last post: by
7 posts views Thread by ilona | last post: by
3 posts views Thread by Dominique Vandensteen | last post: by
7 posts views Thread by L. Scott M. | last post: by
14 posts views Thread by Scott M. | last post: by
1 post views Thread by schoedl | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.