小编im_*_*ous的帖子

python __main__ 和 __init__ 正确使用

因为我对 python 比较陌生,所以语言的这个特殊方面对我来说仍然不透明。

因此,假设我的项目包含许多文件,其中包含执行操作的代码和两个“服务”文件:__init__.py__main__.py

__init__.py只有:

if __name__ == "__main__":
    import package.__main__
    __main__.main()
Run Code Online (Sandbox Code Playgroud)

并在__main__.py如下:

import package # ok
import package2 # ok

def main():
    package.myfunc1() # can't find reference to myfunc1
    package2.myfunc2() # can't find reference to myfunc2
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:为什么两个包都可见而里面的函数不可见?我已经从谷歌阅读了一些源代码,但仍然无法发现它和我的代码之间的区别。我正在使用Python 3.5.1

我认为,在该代码__init__将推出__main____main__将推出的我的其余功能。

UPD

好吧,如果我将某人与我的代码混淆,我深表歉意。支持的想法__init__.py是该文件是在添加第一个包时由 IDE 创建的,所以我决定用在第一个 github 条目中找到的代码填充它(我的错,我虽然它可以通过复制粘贴重新使用)。

严格来说,我只需要 python 构造,相当于这个 C 代码:

header.h
void func1(){...} //in code1.c
void func2(){...} //in code2.c
#include "header.h" …
Run Code Online (Sandbox Code Playgroud)

python program-entry-point initialization

8
推荐指数
2
解决办法
2万
查看次数

使用bouncycastle的椭圆曲线点加法

我的问题很简单:我需要在Fp使用Java时添加两点.一旦java api缺少一些ecc utils我就会使用bouncycastle.

以下是使用的公式:

P + Q = -R
? = (yq - yp)/(xq-xp)
?r = -yp + ?(xp - xr)
xr = ?^2 - xp - xq
Run Code Online (Sandbox Code Playgroud)

并在java中快速实现上面的公式:

String newline = System.lineSeparator();
BigInteger yp = new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280");
BigInteger yq = new BigInteger("17614944419213781543809391949654080031942662045363639260709847859438286763994");
BigInteger xp = new BigInteger("2");
BigInteger xq = new BigInteger("57520216126176808443631405023338071176630104906313632182896741342206604859403");
BigInteger p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041");
BigInteger a_ = new BigInteger("7");
BigInteger b_ = new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414");
ECFieldElement x1 = new ECFieldElement.Fp(p, xp);
ECFieldElement y1 = new …
Run Code Online (Sandbox Code Playgroud)

java bouncycastle elliptic-curve

3
推荐指数
1
解决办法
1037
查看次数