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
}
5
  • @Anon: How? (I am being equally cryptic!) Commented Jan 12, 2010 at 0: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.
    Commented Jan 12, 2010 at 0:54
  • 4
    Hexadecimal will shave off a few chars... but seriously, PEP8 is a style guide not a style rule.
    – Sufian
    Commented Jan 12, 2010 at 0:55
  • PEP8 is not a law. It's a suggestion. Why are you asking?
    – S.Lott
    Commented Jan 12, 2010 at 1: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
    Commented Jan 12, 2010 at 1:44

6 Answers 6

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.

0
5
'e': 3226833362680126101036263622033066816222202666130162062116461326212012L \
     * 10**45 \
     + 222403311326222666622610430466620224662364142L

I in no way endorse this.

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.

1
  • 3
    Calling and additional function just to follow a style guide is overkill IMHO. Interesting solution though.
    – GmonC
    Commented Jan 12, 2010 at 0: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.

2

import this

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

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/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.