Re: Pythonic list/tuple/dict layout?
In article <871vur39k7@benfinney.id.au>, Ben Finney wrote: > >I actually use this style: > >foo = { >0: 'spam', >1: 'eggs', >2: 'beans', >} > >because that makes it clear that *all* the indented lines are a >continuation of the same statement, just like a suite of statements >are all uniformly indented under (e.g.) a function definition. Ditto -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ Weinberg's Second Law: If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
Akira Kitada writes: > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? It seems that I use both d1 and d4, though in both cases I omit the trailing commas. I use d1 when each item is on a separate line, and d4 when I'm packing them onto multiple lines. e.g., op = XT.make_optparse \ ([('E', 'error', {'action': 'store_const', 'dest': 'type', 'const': 'error', 'help': "Mark the window as reporting an error."}), ## ... ('t', 'title', {'dest': 'title', 'help': "Set the window's title string."})], version = VERSION, usage = '%prog [-EIQWm] [-t TITLE] [-d HEADLINE] ' 'MESSAGE [BUTTONS...]') and service_info = [('watch', T.VERSION, { 'adopted': (0, 0, '', cmd_adopted), 'kick': (1, 1, 'PEER', cmd_kick) })] In this latter case, were I defining multiple services, I'd indent it differently: service_info = [ ('watch', T.VERSION, { 'adopted': (0, 0, '', cmd_adopted), 'kick': (1, 1, 'PEER', cmd_kick) }), ##... ] -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
d1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
> These are the only two that follow PEP 8; the others don't have > four-space indent levels. In those examples, the following sentence in PEP 8 would be applied. "Make sure to indent the continued line appropriately." > I actually use this style: > >foo = { >0: 'spam', >1: 'eggs', >2: 'beans', >} > > because that makes it clear that *all* the indented lines are a > continuation of the same statement, just like a suite of statements > are all uniformly indented under (e.g.) a function definition. > > It seems that the author of the Python editing mode in Emacs agrees > with me too (the style, at least, if not the reasoning), which makes > my programming life easier. Yes, it does, but people around me tend to prefer d1 style to that one. One purpose of this silly thread is to figure out which is most popular one... -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
> BTW, there's no need to use such large examples. Three items per dict > would be sufficient to illustrate the styles, using ten items doesn't add > anything useful to the discussion. I worried to be told 'you can make it in a line like {"ham": "jam", "spam": "alot"}' ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
On Sun, 25 Jan 2009 17:18:28 +0900, Akira Kitada wrote: > Hi, > > There is more than one way to write a list/tuple/dict in Python, and > actually different styles are used in standard library. As a hobgoblin > of little minds, I rather like to know which style is considered > "Pythonic" > in the community. > > I collected common layout from existing code and pasted them below. My > vote would go to d1. How about yours? All of them. BTW, there's no need to use such large examples. Three items per dict would be sufficient to illustrate the styles, using ten items doesn't add anything useful to the discussion. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
Akira Kitada writes: > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? > > If there is consensus on this, that might be worth being included in > PEP 8. > > Thanks, > > """ > d1 = { > 0: "ham", > 1: "jam", > 2: "spam", > 3: "alot", > 4: "knights", > 5: "who", > 6: "say", > 7: "ni", > 8: "dead", > 9: "parrot", > } > > d2 = { > 0: "ham", > 1: "jam", > 2: "spam", > 3: "alot", > 4: "knights", > 5: "who", > 6: "say", > 7: "ni", > 8: "dead", > 9: "parrot",} These are the only two that follow PEP 8; the others don't have four-space indent levels. I actually use this style: foo = { 0: 'spam', 1: 'eggs', 2: 'beans', } because that makes it clear that *all* the indented lines are a continuation of the same statement, just like a suite of statements are all uniformly indented under (e.g.) a function definition. It seems that the author of the Python editing mode in Emacs agrees with me too (the style, at least, if not the reasoning), which makes my programming life easier. -- \ “The future always arrives too fast, and in the wrong order.” | `\—Alvin Toffler | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
When the date was Sunday 25 January 2009, Akira Kitada wrote: > There is more than one way to write a list/tuple/dict in Python, > and actually different styles are used in standard library. I would vote for d1, but I don't think that this is more "pythonic", I just consider it more "clean", according to my personal aesthetic criteria. :> -- Michael Iatrou (yxzb) -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
> Wow! A Python debate over curly brace placement! Imagine that! PEP8 even deals with tabs vs spaces, where to put a blank line, etc :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
On Jan 25, 2:18 am, Akira Kitada wrote: > Hi, > > There is more than one way to write a list/tuple/dict in Python, > and actually different styles are used in standard library. > As a hobgoblin of little minds, I rather like to know which style is > considered "Pythonic" > in the community. > > I collected common layout from existing code and pasted them below. > My vote would go to d1. How about yours? > > If there is consensus on this, that might be worth being included in PEP 8. > > Thanks, > > """ > d1 = { > 0: "ham", > 1: "jam", > 2: "spam", > 3: "alot", > 4: "knights", > 5: "who", > 6: "say", > 7: "ni", > 8: "dead", > 9: "parrot", > > } > [snip] I use d1. Wow! A Python debate over curly brace placement! Imagine that! -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list/tuple/dict layout?
> and pasted them below. > My vote would go to d1. How about yours? > > Whatever reads best within the context of the specific code is Pythonic. -- http://mail.python.org/mailman/listinfo/python-list