Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71452 > unrolled thread

Re: PEP 8 : Maximum line Length :

Started byPeter Otten <__peter__@web.de>
First post2014-05-13 10:45 +0200
Last post2014-05-17 10:46 -0700
Articles 14 — 8 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: PEP 8 : Maximum line Length : Peter Otten <__peter__@web.de> - 2014-05-13 10:45 +0200
    Re: PEP 8 : Maximum line Length : Rustom Mody <rustompmody@gmail.com> - 2014-05-13 06:18 -0700
    Re: PEP 8 : Maximum line Length : wxjmfauth@gmail.com - 2014-05-15 07:17 -0700
      Re: PEP 8 : Maximum line Length : Chris Angelico <rosuav@gmail.com> - 2014-05-16 00:27 +1000
        Re: PEP 8 : Maximum line Length : wxjmfauth@gmail.com - 2014-05-15 08:48 -0700
        Re: PEP 8 : Maximum line Length : albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-05-17 12:52 +0000
          Re: PEP 8 : Maximum line Length : Chris Angelico <rosuav@gmail.com> - 2014-05-17 23:18 +1000
            Re: PEP 8 : Maximum line Length : Roy Smith <roy@panix.com> - 2014-05-17 09:49 -0400
          Re: PEP 8 : Maximum line Length : Tim Chase <python.list@tim.thechases.com> - 2014-05-17 08:28 -0500
            Re: PEP 8 : Maximum line Length : Roy Smith <roy@panix.com> - 2014-05-17 09:46 -0400
          Re: PEP 8 : Maximum line Length : Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-05-17 15:02 +0100
            Re: PEP 8 : Maximum line Length : Roy Smith <roy@panix.com> - 2014-05-17 10:06 -0400
              Re: PEP 8 : Maximum line Length : Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-05-17 15:21 +0100
              Re: PEP 8 : Maximum line Length : Rustom Mody <rustompmody@gmail.com> - 2014-05-17 10:46 -0700

#71452 — Re: PEP 8 : Maximum line Length :

FromPeter Otten <__peter__@web.de>
Date2014-05-13 10:45 +0200
SubjectRe: PEP 8 : Maximum line Length :
Message-ID<mailman.9952.1399970767.18130.python-list@python.org>
Ganesh Pal wrote:

> Hi  Team ,
> 
> 
> what would be the best way to intent the below line .
> 
> I have few lines in my program exceeding the allowed maximum line Length
> of 79./80 characters
> 
> Example 1 :
> 
>    p =
> 
Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
> 
> 
> Iam running pylint and it says  the above line is tool long how do I limit
> it to 79 character without violating any rules
> 
> ************* Module isi_corrupt
> C: 14,0: Line too long (88/80)
> W: 19,0: Bad indentation. Found 6 spaces, expected 8

(1) Newlines are allowed inside an open (, [, or {. So:

p = subprocess.Popen(
    shlex.split(cmd),
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)

Other techniques:

(2) Introduce helper variables:

cmd = shlex.split(cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

(3) Import names:

from subprocess import PIPE
p = subprocess.Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)

(4) Use aliases:

import subprocess as sp
p = sp.Popen(shlex.split(cmd), stdout=sp.PIPE, stderr=sp.PIPE)

[toc] | [next] | [standalone]


#71481

FromRustom Mody <rustompmody@gmail.com>
Date2014-05-13 06:18 -0700
Message-ID<8d2af187-96e9-4367-83f5-d95e7f435734@googlegroups.com>
In reply to#71452
On Tuesday, May 13, 2014 2:15:49 PM UTC+5:30, Peter Otten wrote:
> Ganesh Pal wrote:
> > what would be the best way to intent the below line .
> >    p = Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
> (3) Import names:
> 
> 
> from subprocess import PIPE
> p = subprocess.Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)

Am I missing something basic that nobody has suggested the above
technique iterated once more??

from subprocess import Popen, PIPE
p = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)

[toc] | [prev] | [next] | [standalone]


#71610

Fromwxjmfauth@gmail.com
Date2014-05-15 07:17 -0700
Message-ID<51ad8928-619c-4e9c-b66f-15bd4a2a8124@googlegroups.com>
In reply to#71452
Le mardi 13 mai 2014 10:45:49 UTC+2, Peter Otten a écrit :
> Ganesh Pal wrote:
> 
> 
> 
> > Hi  Team ,
> 
> > 
> 
> > 
> 
> > what would be the best way to intent the below line .
> 
> > 
> 
> > I have few lines in my program exceeding the allowed maximum line Length
> 
> > of 79./80 characters
> 
> > 
> 
> > Example 1 :
> 
> > 
> 
> >    p =
> 
> > 
> 
> Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
> 
> > 
> 
> > 
> 
> > Iam running pylint and it says  the above line is tool long how do I limit
> 
> > it to 79 character without violating any rules
> 
> > 
> 
> > ************* Module isi_corrupt
> 
> > C: 14,0: Line too long (88/80)
> 
> > W: 19,0: Bad indentation. Found 6 spaces, expected 8
> 
> 
> 
> (1) Newlines are allowed inside an open (, [, or {. So:
> 
> 
> 
> p = subprocess.Popen(
> 
>     shlex.split(cmd),
> 
>     stdout=subprocess.PIPE,
> 
>     stderr=subprocess.PIPE)
> 
> 
> 
> Other techniques:
> 
> 
> 
> (2) Introduce helper variables:
> 
> 
> 
> cmd = shlex.split(cmd)
> 
> p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> 
> 
> 
> (3) Import names:
> 
> 
> 
> from subprocess import PIPE
> 
> p = subprocess.Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
> 
> 
> 
> (4) Use aliases:
> 
> 
> 
> import subprocess as sp
> 
> p = sp.Popen(shlex.split(cmd), stdout=sp.PIPE, stderr=sp.PIPE)

=====

One another trick is to drop spaces around keywords

>>> 99999and 12345or 9999999999if 'a'in'a' else 88888888or 777777
12345

and pray, the tools from those who are wasting their time in
writing code analyzers or syntax colorizers or doc strings
collectors or ... are finally working. Depending of the tools
the interpretation may vary, but definitely all are producing
erroneous results.

jmf

[toc] | [prev] | [next] | [standalone]


#71612

FromChris Angelico <rosuav@gmail.com>
Date2014-05-16 00:27 +1000
Message-ID<mailman.10041.1400164039.18130.python-list@python.org>
In reply to#71610
On Fri, May 16, 2014 at 12:17 AM,  <wxjmfauth@gmail.com> wrote:
> One another trick is to drop spaces around keywords
>
>>>> 99999and 12345or 9999999999if 'a'in'a' else 88888888or 777777
> 12345
>
> and pray, the tools from those who are wasting their time in
> writing code analyzers or syntax colorizers or doc strings
> collectors or ... are finally working. Depending of the tools
> the interpretation may vary, but definitely all are producing
> erroneous results.

Yes. Another very effective way to get your code below 80 characters
is to shorten all names to a single letter. Since you don't need to
restrict yourself to monocase Roman letters (as I had to in my
earliest programming days, in BASIC), it's actually quite practical to
uniquely name everything in a single character; you could save
enormous amounts of horizontal space. Then, aggressively "import as"
to do the same with remote symbols (you might need two characters for
those), and you'll be able to write everything in just a few tight
symbols!

ChrisA

[toc] | [prev] | [next] | [standalone]


#71619

Fromwxjmfauth@gmail.com
Date2014-05-15 08:48 -0700
Message-ID<bbf4c211-49a1-41f1-bc2a-d59123577a3b@googlegroups.com>
In reply to#71612
Le jeudi 15 mai 2014 16:27:16 UTC+2, Chris Angelico a écrit :
> On Fri, May 16, 2014 at 12:17 AM,  <wxjmfauth@gmail.com> wrote:
> 
> > One another trick is to drop spaces around keywords
> 
> >
> 
> >>>> 99999and 12345or 9999999999if 'a'in'a' else 88888888or 777777
> 
> > 12345
> 
> >
> 
> > and pray, the tools from those who are wasting their time in
> 
> > writing code analyzers or syntax colorizers or doc strings
> 
> > collectors or ... are finally working. Depending of the tools
> 
> > the interpretation may vary, but definitely all are producing
> 
> > erroneous results.
> 
> 
> 
> Yes. Another very effective way to get your code below 80 characters
> 
> is to shorten all names to a single letter. Since you don't need to
> 
> restrict yourself to monocase Roman letters (as I had to in my
> 
> earliest programming days, in BASIC), it's actually quite practical to
> 
> uniquely name everything in a single character; you could save
> 
> enormous amounts of horizontal space. Then, aggressively "import as"
> 
> to do the same with remote symbols (you might need two characters for
> 
> those), and you'll be able to write everything in just a few tight

=========

>>> 1or 0
1
>>>

Short, but still a bug.

1

[toc] | [prev] | [next] | [standalone]


#71680

Fromalbert@spenarnc.xs4all.nl (Albert van der Horst)
Date2014-05-17 12:52 +0000
Message-ID<53775b9c$0$27160$e4fe514c@dreader35.news.xs4all.nl>
In reply to#71612
In article <mailman.10041.1400164039.18130.python-list@python.org>,
Chris Angelico  <rosuav@gmail.com> wrote:
>On Fri, May 16, 2014 at 12:17 AM,  <wxjmfauth@gmail.com> wrote:
>> One another trick is to drop spaces around keywords
>>
>>>>> 99999and 12345or 9999999999if 'a'in'a' else 88888888or 777777
>> 12345
>>
>> and pray, the tools from those who are wasting their time in
>> writing code analyzers or syntax colorizers or doc strings
>> collectors or ... are finally working. Depending of the tools
>> the interpretation may vary, but definitely all are producing
>> erroneous results.
>
>Yes. Another very effective way to get your code below 80 characters
>is to shorten all names to a single letter. Since you don't need to
>restrict yourself to monocase Roman letters (as I had to in my
>earliest programming days, in BASIC), it's actually quite practical to
>uniquely name everything in a single character; you could save
>enormous amounts of horizontal space. Then, aggressively "import as"
>to do the same with remote symbols (you might need two characters for
>those), and you'll be able to write everything in just a few tight
>symbols!

That may be tong-in-cheek but mathematicians do exactly that. We
use roman, greek and hebrew alphabets in normal italics and boldface
and then some special characters for element-of, logical-or, integral signs,
triangles and what not. Underbarred and upper twiggled, as a suffix a prefix
or a superfix. All in the name of avoiding names longer than one character.

When we run out then there are creative ways to combine known characters
into Jacobi symbols and choose functions.

There are even conventions that allow to leave out characters, like
"juxtaposition means multiplication" and the Einstein summation convention.

You have to invest but terseness pays off.

Now translate E=mc^2 into Java.

>
>ChrisA
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#71683

FromChris Angelico <rosuav@gmail.com>
Date2014-05-17 23:18 +1000
Message-ID<mailman.10083.1400332708.18130.python-list@python.org>
In reply to#71680
On Sat, May 17, 2014 at 10:52 PM, Albert van der Horst
<albert@spenarnc.xs4all.nl> wrote:
> That may be tong-in-cheek but mathematicians do exactly that. We
> use roman, greek and hebrew alphabets in normal italics and boldface
> and then some special characters for element-of, logical-or, integral signs,
> triangles and what not. Underbarred and upper twiggled, as a suffix a prefix
> or a superfix. All in the name of avoiding names longer than one character.
>
> When we run out then there are creative ways to combine known characters
> into Jacobi symbols and choose functions.
>
> There are even conventions that allow to leave out characters, like
> "juxtaposition means multiplication" and the Einstein summation convention.

This, I think, is the main reason for the one-character variable name
convention. Why else are there subscripts? Instead of using "V0"
(two-character name), you use "V₀" (one-character name with a
subscript tag on it) to avoid collision with multiplication.

> Now translate E=mc^2 into Java.

Dunno, but in Python it would be:

assert E==m*c*c

And would probably fail, because that's all floating point :)

ChrisA

[toc] | [prev] | [next] | [standalone]


#71689

FromRoy Smith <roy@panix.com>
Date2014-05-17 09:49 -0400
Message-ID<roy-13D9A0.09495817052014@news.panix.com>
In reply to#71683
In article <mailman.10083.1400332708.18130.python-list@python.org>,
 Chris Angelico <rosuav@gmail.com> wrote:

> On Sat, May 17, 2014 at 10:52 PM, Albert van der Horst
> <albert@spenarnc.xs4all.nl> wrote:
> > That may be tong-in-cheek but mathematicians do exactly that. We
> > use roman, greek and hebrew alphabets in normal italics and boldface
> > and then some special characters for element-of, logical-or, integral signs,
> > triangles and what not. Underbarred and upper twiggled, as a suffix a prefix
> > or a superfix. All in the name of avoiding names longer than one character.
> >
> > When we run out then there are creative ways to combine known characters
> > into Jacobi symbols and choose functions.
> >
> > There are even conventions that allow to leave out characters, like
> > "juxtaposition means multiplication" and the Einstein summation convention.
> 
> This, I think, is the main reason for the one-character variable name
> convention. Why else are there subscripts? Instead of using "V0"
> (two-character name), you use "V?" (one-character name with a
> subscript tag on it) to avoid collision with multiplication.
> 
> > Now translate E=mc^2 into Java.
> 
> Dunno, but in Python it would be:
> 
> assert E==m*c*c
> 
> And would probably fail, because that's all floating point :)
> 
> ChrisA

Nah.  Python has relativistic duck typing:

>>> c = 186000
>>> m = 100
>>> E = 3459600000000L
>>> assert E==m*c*c
>>>

[toc] | [prev] | [next] | [standalone]


#71685

FromTim Chase <python.list@tim.thechases.com>
Date2014-05-17 08:28 -0500
Message-ID<mailman.10085.1400333338.18130.python-list@python.org>
In reply to#71680

[Multipart message — attachments visible in raw view] — view raw

On 2014-05-17 12:52, Albert van der Horst wrote:
> Now translate E=mc^2 into Java.

I suspect it would be something like

public class Einstein  {
  private double mass=0, energy=0;
  public class Relativity implements IEquation {
    Relativity(double mass) {
      set_mass(mass);
    }
    public double getEnergy() {return energy;}
    public double setEnergy(double newEnergy) {
      energy = newEnergy;
      mass = newEnergy / (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT);
    }
    public double get_mass() {return mass;}
    public double setMass(double newMass) {
      mass = newMass;
      energy = newMass * (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT);
    }
  }
  
  public static void main(String[] args) {
    Relativity relativity = new Relativity(
      Integer.parseInt(args[1])
      );
    System.out.println(relativity.getEnergy())
  }
}


(untested, as it has been a long time since I've touched any Java code)

-tkc



[toc] | [prev] | [next] | [standalone]


#71687

FromRoy Smith <roy@panix.com>
Date2014-05-17 09:46 -0400
Message-ID<roy-6B8EE9.09464317052014@news.panix.com>
In reply to#71685
In article <mailman.10085.1400333338.18130.python-list@python.org>,
 Tim Chase <python.list@tim.thechases.com> wrote:

> On 2014-05-17 12:52, Albert van der Horst wrote:
> > Now translate E=mc^2 into Java.
> 
> I suspect it would be something like
> 
> public class Einstein  {
>   private double mass=0, energy=0;
>   public class Relativity implements IEquation {
>     Relativity(double mass) {
>       set_mass(mass);
>     }
>     public double getEnergy() {return energy;}
>     public double setEnergy(double newEnergy) {
>       energy = newEnergy;
>       mass = newEnergy / (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT);
>     }
>     public double get_mass() {return mass;}
>     public double setMass(double newMass) {
>       mass = newMass;
>       energy = newMass * (units.SPEED_OF_LIGHT * units.SPEED_OF_LIGHT);
>     }
>   }
>   
>   public static void main(String[] args) {
>     Relativity relativity = new Relativity(
>       Integer.parseInt(args[1])
>       );
>     System.out.println(relativity.getEnergy())
>   }
> }
> 
> 
> (untested, as it has been a long time since I've touched any Java code)
> 
> -tkc

Not good enough.  Einstein should really be a singleton, so you need 
something like an AbstractScientistFactory, which implements Singleton.  
And you really should be importing 
SPEED_OF_LIGHT_IN_VACUUM_METERS_PER_SECOND from 
org.universe.physics.constants.  And you need to declare that 
Einstein.getEnergy() raises NumericValueOutOfBoundsError if mass is 
negative (and FlatEarthError if the code is run in certain states south 
of the Mason-Dixie line).

[toc] | [prev] | [next] | [standalone]


#71691

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-05-17 15:02 +0100
Message-ID<mailman.10088.1400335366.18130.python-list@python.org>
In reply to#71680
On 17/05/2014 13:52, Albert van der Horst wrote:
>
> Now translate E=mc^2 into Java.
>

I can't do that as I simply don't understand it.  What has the 
Marylebone Cricket Club got to do with E?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#71692

FromRoy Smith <roy@panix.com>
Date2014-05-17 10:06 -0400
Message-ID<roy-85B3C7.10061917052014@news.panix.com>
In reply to#71691
In article <mailman.10088.1400335366.18130.python-list@python.org>,
 Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:

> On 17/05/2014 13:52, Albert van der Horst wrote:
> >
> > Now translate E=mc^2 into Java.
> >
> 
> I can't do that as I simply don't understand it.  What has the 
> Marylebone Cricket Club got to do with E?

A wicket looks like an E on its side.  Does that help?

[toc] | [prev] | [next] | [standalone]


#71694

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-05-17 15:21 +0100
Message-ID<mailman.10089.1400336487.18130.python-list@python.org>
In reply to#71692
On 17/05/2014 15:06, Roy Smith wrote:
> In article <mailman.10088.1400335366.18130.python-list@python.org>,
>   Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>
>> On 17/05/2014 13:52, Albert van der Horst wrote:
>>>
>>> Now translate E=mc^2 into Java.
>>>
>>
>> I can't do that as I simply don't understand it.  What has the
>> Marylebone Cricket Club got to do with E?
>
> A wicket looks like an E on its side.  Does that help?
>

Ah, now I get it, thanks for that :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#71702

FromRustom Mody <rustompmody@gmail.com>
Date2014-05-17 10:46 -0700
Message-ID<7e8afb04-d563-4cac-9957-32bd6b0d4dec@googlegroups.com>
In reply to#71692
On Saturday, May 17, 2014 7:36:19 PM UTC+5:30, Roy Smith wrote:
> 
>  Mark Lawrence  wrote:
> > > Now translate E=mc^2 into Java.
> > >
> > 
> > I can't do that as I simply don't understand it.  What has the 
> > Marylebone Cricket Club got to do with E?
> 
> A wicket looks like an E on its side.  Does that help?

Heh! Imaginative!

Now spend your life meditating on all the glyphs that inhabit unicode.
And mon cher u-no-hoo will award you with an epiphany.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web