Brian Quinlan wrote: > year, month, day = time.localtime()[0:3] > > or > > year, month, day, *dummy = time.localtime() I think Gareth's split example is better. localtime returns a fixed-length tuple. Things are much more interesting when you don't know how many elements you're getting. Which do you like better for, say, parsing required and optional parameters to a command: (cmd, req1, req2, req3, opt_str) = input.split(None, 4) opts = opt_str.split() execute_cmd(cmd, req1, req2, req3, opts) or parts = input.split() (cmd, req1, req2, req3) = parts[:4] opts = parts[4:] execute_cmd(cmd, req1, req2, req3, opts) or (cmd, req1, req2, req3, *opts) = input.split() execute_cmd(cmd, req1, req2, req3, opts) A really interesting possibility is: (first, *middle, last) = input.split() This breaks the parallel to parameter passing, but would be very handy. Are we getting too perlish? -- Nathan Clegg GeerBox nathan-nntp@geerbox.com
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4