12

This is somehow related to question about big strings and PEP8.

How can I make my script that has the following line PEP8 compliant ("Maximum Line Length" rule)?

pub_key = {
   'e': 3226833362680126101036263622033066816222202666130162062116461326212012222403311326222666622610430466620224662364142L,
   'n': 226421003861041248462826226103022608220328242204422684232640331238220232226321616266146243302342688266846281802662666622213868114632268211186223606846623310006662260110460620201618186828411322260686632603226636226662262862212140221422102106336342228236361106240226122644614266186283436228208626640846820224661642086022346422443282224682686612228404266842316822624342226666622264826123822122031361242246432886612624262663222232331438863220022020826266366016100422L
}
Community
  • 1
  • 1
parxier
  • 3,811
  • 5
  • 42
  • 54
  • @Anon: How? (I am being equally cryptic!) – Alok Singhal Jan 12 '10 at 00:50
  • Not too familiar with Python syntax, but assuming it's possible to perform arithmetic in this declaration, it would be something like `32268333626801261010362 * pow(10, howevermany)`, and then add more on each successive line. – Anon. Jan 12 '10 at 00:54
  • 4
    Hexadecimal will shave off a few chars... but seriously, PEP8 is a style _guide_ not a style _rule_. – Sufian Jan 12 '10 at 00:55
  • PEP8 is not a law. It's a suggestion. Why are you asking? – S.Lott Jan 12 '10 at 01:40
  • 4
    No-one's going to need to read those numbers; let them overflow and scroll. (80 characters is too restrictive at the best of times; sticking to it here has no benefit.) – bobince Jan 12 '10 at 01:44

6 Answers6

22

But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply. When in doubt, use your best judgment.

source

In this case, I would just leave the big integers as is.

GmonC
  • 10,924
  • 1
  • 30
  • 38
5
'e': 3226833362680126101036263622033066816222202666130162062116461326212012L \
     * 10**45 \
     + 222403311326222666622610430466620224662364142L

I in no way endorse this.

danben
  • 80,905
  • 18
  • 123
  • 145
5

best way I can think of is

pub_key = {
   'e': long('3226833362680126101036263622033066816222202666130162062116461326'
             '212012222403311326222666622610430466620224662364142'),
   'n': long('2264210038610412484628262261030226082203282422044226842326403312'
             '3822023222632161626614624330234268826684628180266266662221386811'
             '4632268211186223606846623310006662260110460620201618186828411322'
             '2606866326032266362266622628622121402214221021063363422282363611'
             '0624022612264461426618628343622820862664084682022466164208602234'
             '6422443282224682686612228404266842316822624342226666622264826123'
             '8221220313612422464328866126242626632222323314388632200220208262'
             '66366016100422'),
}

exactly 80 chars.

nosklo
  • 217,122
  • 57
  • 293
  • 297
  • 3
    Calling and additional function just to follow a style guide is overkill IMHO. Interesting solution though. – GmonC Jan 12 '10 at 00:56
2

I don't think you can. The guidelines in PEP8 are guidelines, there are situations where it's just not possible to follow the guideline.

James Polley
  • 7,977
  • 2
  • 29
  • 33
2

import this

... Special cases aren't special enough to break the rules. Although practicality beats purity. ...

Ipsquiggle
  • 1,814
  • 1
  • 15
  • 25
1

This can be done. Long lines can be broken over multiple lines by wrapping expressions in parentheses. Here is where it is explained:

http://www.python.org/dev/peps/pep-0008/

Robert
  • 11
  • 2