python:用pyinstaller作個排列組合的小工具

排列組合用處不少,因此打算本身作個這個工具:python

from scipy.special import comb,perm
from os import system
N=int(input('NumberOfThings:'))
k=int(input('NumberOfElementsTaken:'))
print('從%d裏面取出%d個元素:'%(N,k))
print('排列:')
print(perm(N,k,exact=True))#exact T 返回長整,F返回浮點
print('組合:')
print(comb(N,k,exact=True))
system('pause')

核心就是兩句:函數

from scipy.special import comb,perm
print(perm(N,k,exact=True))#exact T 返回長整,F返回浮點
print(comb(N,k,exact=True))

真方便,因而跑去用pyinstaller打包......工具

居然失敗了,若干支持庫找不到.........我擦code

趕忙寫個hello world 打個包,看看是否是pyinstaller炸了.blog

然而一切正常......ip

嗯,是的,我遇到了pyinstaller不支持的狀況了.ci

怎麼辦呢?本身寫了一個,實現了浮點數運算,但是我想要的是python的長整型啊!!!!.算了,仍是去複製黏貼一下吧....因而打開perm 和 comb的實現部分,開始找代碼.好坑,組合竟然有個函數引用的是pyd裏面的.....,只好原封不動的搬過來了.element

因而爲了適應pyinstaller的版本出現了:input

from _comb import _comb_int

def pailie(N,k):
    if (k > N) or (N < 0) or (k < 0):
        return 0
    val = 1
    for i in range(N - k + 1, N + 1):
        val *= i
    return val
def zuhe(N,k):
    return _comb_int(N, k)

while True:
    ctl=''
    ctl=input('input 0 to exit,anything else to proceed:')
    if ctl=='0':
        break
    N=int(input('Number of things:'))
    k=int(input('Number of elements taken'))
    print('排列:')
    print(pailie(N,k))
    print('組合:')
    print(zuhe(N,k))

把這個源文件和_comb.cp36-win_amd64.pyd一塊兒從工程裏考出來,找個文件夾塞進去,pyinstaller一下......嘿嘿嘿,成功了.整個綠色軟件10.6兆,好吧,有點肥.it

這樣,就有了一個順手的小工具了,哈哈

相關文章
相關標籤/搜索