[Tutor] Long Lines techniques
Avi Gross
avigross at verizon.net
Thu Dec 13 19:45:31 EST 2018
Just for you Bob, I will make this short.
Here is the most bizarre solution as you might agree.
Edit a file of python code. Use lines as long as it takes. Make sure it works.
Edit the file again and split lines in a way that does not mess up indentation. Meaning, use a normal text editor, not one that understands python.
At the end of each line you cut, place a marker that makes sense. For example “!EOL” that may be easier to read or print (or harder) but not to edit.
Save all this to another plain file. It is not valid python.
Write a real python file that contains a function with a name like outclude(filename) that opens a file, reads in the entire file, replaces every place with the marker at the end of the line with NOTHING, effectively splicing it to the next line. It then returns a string containing your entire program with proper indentation.
Finally:
eval(outclude("filename"))
SKIPPING the other 98% this post could have had. Just an example:
DISCLAIMER: The above was posted as a sick form of humor, only. Any resemblance to reality is unintentional. But note, some languages do have a phase of scanning that would allow tricks like this in a pre-processor.
From: Bob Gailer <bgailer at gmail.com>
Sent: Thursday, December 13, 2018 2:33 PM
To: Avi Gross <avigross at verizon.net>
Cc: tutor at python.org
Subject: Re: [Tutor] Long Lines techniques
On Dec 13, 2018 1:51 PM, "Avi Gross" <avigross at verizon.net <mailto:avigross at verizon.net> > wrote:
>
> Simple question:
Avi: when I see an email from you I tend to ignore it because it always seems to lead to something that is long, time consuming and complex. Would you consider finding ways to make your questions or comments a lot briefer?
I will be more inclined to read them if they are briefer.
You have correctly determined the conditions that will lead to continuation lines without backslash. I think we tend to use whatever is convenient.
In your example of a list comprehension over multiple lines there is no indentation. There is just a lot of white space. You might look at it this way: the compiler sees a left bracket with no corresponding right bracket on that line. So it assumes that there's more to the statement on the next line, it ignores the newline and just continues. Indentation is only significant if it starts at the beginning of a statement.
Hope this helps
Bob gailer
More information about the Tutor
mailing list