PEP8 - 80 个字符 - 大整数

发布于 2024-08-17 16:29:52 字数 802 浏览 2 评论 0原文

这在某种程度上与有关大字符串和 PEP8 的问题相关。

如何使我的脚本具有以下行 PEP8 兼容(“最大行长度”规则)?

pub_key = {
   'e': 3226833362680126101036263622033066816222202666130162062116461326212012222403311326222666622610430466620224662364142L,
   'n': 226421003861041248462826226103022608220328242204422684232640331238220232226321616266146243302342688266846281802662666622213868114632268211186223606846623310006662260110460620201618186828411322260686632603226636226662262862212140221422102106336342228236361106240226122644614266186283436228208626640846820224661642086022346422443282224682686612228404266842316822624342226666622264826123822122031361242246432886612624262663222232331438863220022020826266366016100422L
}

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
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

寻找一个思念的角度 2024-08-24 16:29:52

但最重要的是:知道什么时候该做
不一致——有时是风格
指南并不适用。当在
如有疑问,请运用您的最佳判断。

source

在这种情况下,我将保留大整数不变。

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.

骄兵必败 2024-08-24 16:29:52
'e': 3226833362680126101036263622033066816222202666130162062116461326212012L \
     * 10**45 \
     + 222403311326222666622610430466620224662364142L

我绝不赞同这一点。

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

I in no way endorse this.

甜妞爱困 2024-08-24 16:29:52

我能想到的最好的办法就是

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

80个字符。

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.

撞了怀 2024-08-24 16:29:52

我认为你不能。 PEP8 中的指南只是指南,在某些情况下无法遵循该指南。

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.

蓝海似她心 2024-08-24 16:29:52

导入这个

...
特殊情况还不足以违反规则。
尽管实用性胜过纯粹性。
...

import this

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

趁微风不噪 2024-08-24 16:29:52

这是可以做到的。通过将表达式括在括号中,可以将长行分成多行。这是解释的地方:

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文