Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > writing code over several lines

Reply
Thread Tools

writing code over several lines

 
 
Dominik Kaspar
Guest
Posts: n/a
 
      10-17-2003
i want to initialize a constant list at the beginning of a python
program. but the list is too big for one line. is there any
possibility to spread the list over several lines, so that the code
looks neat again?

something like:
LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
[400, 401, 402], [500, 501, 502], [600, 601, 602],
[700, 701, 702], [800, 801, 802], [900, 901, 902]]

thanks in advance
dominik
 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      10-17-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Dominik Kaspar) wrote:

> LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
> [400, 401, 402], [500, 501, 502], [600, 601, 602],
> [700, 701, 702], [800, 801, 802], [900, 901, 902]]


Might I suggest trying the above and seeing what happens?
 
Reply With Quote
 
 
 
 
anton muhin
Guest
Posts: n/a
 
      10-17-2003
Dominik Kaspar wrote:
> i want to initialize a constant list at the beginning of a python
> program. but the list is too big for one line. is there any
> possibility to spread the list over several lines, so that the code
> looks neat again?
>
> something like:
> LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
> [400, 401, 402], [500, 501, 502], [600, 601, 602],
> [700, 701, 702], [800, 801, 802], [900, 901, 902]]
>
> thanks in advance
> dominik


yes. Just type the code and feed it to python interpreter:

LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
[400, 401, 402], [500, 501, 502], [600, 601, 602],
[700, 701, 702], [800, 801, 802], [900, 901, 902]]
print LIST

[[100, 101, 102], [200, 201, 202], [300, 301, 302], ...

regards,
anton.

 
Reply With Quote
 
Boris Boutillier
Guest
Posts: n/a
 
      10-17-2003
Just some coding ideas :
List = [
[100,101,102]
, [200,201,202]
, [300,301,302]
, .....
]
Can make things clearer and sometimes worse.

Boris

On Fri, 17 Oct 2003 06:56:48 -0700, Dominik Kaspar wrote:

> i want to initialize a constant list at the beginning of a python
> program. but the list is too big for one line. is there any
> possibility to spread the list over several lines, so that the code
> looks neat again?
>
> something like:
> LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
> [400, 401, 402], [500, 501, 502], [600, 601, 602],
> [700, 701, 702], [800, 801, 802], [900, 901, 902]]
>
> thanks in advance
> dominik


 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      10-17-2003
Dominik Kaspar wrote:
>
> i want to initialize a constant list at the beginning of a python
> program. but the list is too big for one line. is there any
> possibility to spread the list over several lines, so that the code
> looks neat again?
>
> something like:
> LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
> [400, 401, 402], [500, 501, 502], [600, 601, 602],
> [700, 701, 702], [800, 801, 802], [900, 901, 902]]


Did you know that you can run Python directly and get an interactive
interpreter, where you could try out code like the above and
see what it does? This and other helpful things are covered in
the online tutorial at http://www.python.org/doc/current/tut/tut.html

-Peter
 
Reply With Quote
 
Gary Herron
Guest
Posts: n/a
 
      10-17-2003
> LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
> [400, 401, 402], [500, 501, 502], [600, 601, 602],
> [700, 701, 702], [800, 801, 802], [900, 901, 902]]


There are several ways to do it.

Anything within [...], (...) or {...} can span lines and needs follow
NO indent rules. So your example works just as it is.

Another way is to end any line with a backslash. Then the following
line is logically appended to the current line, and again its indent
is irrelevant. I rarely use this because I think it's ugly and because
I can put almost anything between parentheses.

Gary Herron



 
Reply With Quote
 
rzed
Guest
Posts: n/a
 
      10-18-2003

"Boris Boutillier" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Just some coding ideas :
> List = [
> [100,101,102]
> , [200,201,202]
> , [300,301,302]
> , .....
> ]
> Can make things clearer and sometimes worse.
>


Boris, you are aware that the last member of a Python list can have a
trailing comma, aren't you? In my opinion, this:
List = [
[100,101,102],
[200,201,202],
[300,301,302],
]
is at least as clear, and does not force the unnatural binding of a leading
comma to what follows.

--
rzed



 
Reply With Quote
 
Wojtek Walczak
Guest
Posts: n/a
 
      10-21-2003
Dnia 17 Oct 2003 06:56:48 -0700, Dominik Kaspar napisał(a):
> i want to initialize a constant list at the beginning of a python
> program. but the list is too big for one line. is there any
> possibility to spread the list over several lines, so that the code
> looks neat again?
>
> something like:
> LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
> [400, 401, 402], [500, 501, 502], [600, 601, 602],
> [700, 701, 702], [800, 801, 802], [900, 901, 902]]


The above is correct, but use tuples instead.

--
[ Wojtek Walczak - gminick (at) underground.org.pl ]
[ <http://gminick.linuxsecurity.pl/> ]
[ "...rozmaite zwroty, matowe od patyny dawnosci." ]

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      10-21-2003
Wojtek Walczak wrote:
>
> Dnia 17 Oct 2003 06:56:48 -0700, Dominik Kaspar napisał(a):
> > i want to initialize a constant list at the beginning of a python
> > program. but the list is too big for one line. is there any
> > possibility to spread the list over several lines, so that the code
> > looks neat again?
> >
> > something like:
> > LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
> > [400, 401, 402], [500, 501, 502], [600, 601, 602],
> > [700, 701, 702], [800, 801, 802], [900, 901, 902]]

>
> The above is correct, but use tuples instead.


No need. Why do you suggest that? I think the advice goes against
typical Python programming style in this case.

-Peter
 
Reply With Quote
 
Jp Calderone
Guest
Posts: n/a
 
      10-21-2003
> Dnia 17 Oct 2003 06:56:48 -0700, Dominik Kaspar napisa?(a):
> > i want to initialize a constant list at the beginning of a python
> > program. but the list is too big for one line. is there any
> > possibility to spread the list over several lines, so that the code
> > looks neat again?
> >
> > something like:
> > LIST = [[100, 101, 102], [200, 201, 202], [300, 301, 302],
> > [400, 401, 402], [500, 501, 502], [600, 601, 602],
> > [700, 701, 702], [800, 801, 802], [900, 901, 902]]


LIST = [range(x, x + 3) for x in range(100, 1000, 100)]

blindly-optimizing-the-example-you-give'ly,

Jp

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/lU02edcO2BJA+4YRAiYcAKCpTaEUC+FvdDpwp2Ajj1gVUV+0rg CeNjSZ
JrkT9LggBjILOr6ZhpnUNqk=
=HoH4
-----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
Regexp to search over several lines in one string d99alu@efd.lth.se Perl Misc 8 01-28-2008 06:31 PM
sgub stretching over several lines Jan Ask Ruby 6 08-06-2007 02:20 AM
RDOC: several related modules in several C files Victor \Zverok\ Shepelev Ruby 3 03-16-2007 04:15 PM
SEVERAL LINES IS TITLE PROPERTY OF CELL RootShell HTML 4 07-14-2004 09:58 AM



Advertisments