Re: Best way to split up lines - RE: About the 79 character line recommendation
Michael Yanowitz schreef: > Hello: > >I too don't like large lines. However in the following case, and > multi-level indentations, I find it unavoidable. >Here is one huge statement I haven't been able to split onto multiple > lines. > What would be the best way to split the following line (Python doesn't like > me > to split it up between the comma-separated parameters): > > top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, > utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, > st2, st3, st4, st5, st6, numberOfLabels, dataWord = > struct.unpack("!H4BH20BHI", strMessage) I see three possibilities: 1. Avoid the one-liner alltogether u = struct.unpack("!H4BH20BHI", strMessage) top = u[0] ip1, ip2, ip3, ip4 = u[1:5] messageCounter = u[6] # ... and so on ... In this approach with your example it seems to me to be a good idea to put ip, utc and st in separate tuples like this: u = struct.unpack("!H4BH20BHI", strMessage) top = u[0] ip = u[1:5] messageCounter = u[5] ackRequired = u[6] dataType = u[7] utc = u[8:20] st = u[20:26] numberOfLabels = u[26] dataWord = u[27] 2. Use parens around the tuple on the left hand side (top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6, numberOfLabels, dataWord) = struct.unpack("!H4BH20BHI", strMessage) 3. Use '\' to break the line top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, \ utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, \ utc12, st1, st2, st3, st4, st5, st6, numberOfLabels, dataWord \ = struct.unpack("!H4BH20BHI", strMessage) -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Best way to split up lines - RE: About the 79 character line recommendation
Hello: I too don't like large lines. However in the following case, and multi-level indentations, I find it unavoidable. Here is one huge statement I haven't been able to split onto multiple lines. What would be the best way to split the following line (Python doesn't like me to split it up between the comma-separated parameters): top, ip1, ip2, ip3, ip4, messageCounter, ackRequired, dataType, utc1, utc2, utc3, utc4, utc5, utc6, utc7, utc8, utc9, utc10, utc11, utc12, st1, st2, st3, st4, st5, st6, numberOfLabels, dataWord = struct.unpack("!H4BH20BHI", strMessage) Thanks in advance: Michael Yanowitz -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Ramon Diaz-Uriarte Sent: Wednesday, December 06, 2006 5:12 PM To: Steve Bergman Cc: python-list@python.org Subject: Re: About the 79 character line recommendation On 5 Dec 2006 13:28:22 -0800, Steve Bergman <[EMAIL PROTECTED]> wrote: (...) > > I'm finding 100 to be a nice balance. It forces me not to be lazy and > allow really long lines, but allows me to format so as to make the > meaning most clear. > But if you use some advanced editors (such as Emacs) that easily allow you to see/edit the same file in two buffers side by side, then going beyond 80 chars is often a bad idea, specially if you use a laptop. (And, of course, there is the eternal issue of doing a simple "a2ps" to print some code; longer than 80 and you often have hard to read pages). Best, R. -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list