简体   繁体   English

py2exe输入不起作用

[英]py2exe input not working

My little bit of code (it's not all but I think it's all that is needed): 我的一点点代码(不是全部,但我认为这是所有需要的):

functions = {'1':cels_kelw, '2':cels_farh, '3':cels_kelw, '4':kelw_farh, '5':cels_farh, '6':kelw_farh}
while True:
    operation = raw_input("Choose number:\n")
    if operation == '7':
        print 'PROGRAM ENDED'
        break
    try:
        chosenFunction = functions.get(operation)
        if (operation == '3') or (operation == '5') or (operation == '6'):
            turn = 1
        else:
            turn = 0
        print ("Result of your conversion is {num}".format(num = chosenFunction(get_float(), turn)))
    except NameError:
        print("Function you have chosen doesn't exists or you have put wrong type of data")

Now, when I run it in python interpreter it works well, when I am asked to choose function and it exists - there's no exception and it throws me result of the picked function. 现在,当我在python解释器中运行它时,它运行良好,当我被要求选择函数并且它存在时-没有异常,它使我选择了函数。

When I converted it to .exe with py2exe it asks me to input number of function in my mind but it doesn't work. 当我用py2exe将其转换为.exe时,它要求我在脑海中输入函数的数量,但是它不起作用。 After putting number (for ex. 1) it asks me for a number again. 输入数字后(例如1),它再次要求我输入数字。

What's wrong with this code? 此代码有什么问题? Thanks for help. 感谢帮助。

I suppose those functions are defined in another python module. 我想这些功能是在另一个python模块中定义的。 And you missed that writting your setup.py file. 而且您错过了编写setup.py文件的过程。

You have to add all python modules/packages to the setup.py . 您必须将所有python模块/软件包添加到setup.py

Edit 编辑

Just a feeling but, Could you add an else statement after the break ? 只是一种感觉,但是,您可以在break后添加else语句吗?

 if operation == '7':
        print 'PROGRAM ENDED'
        break
 else: # Add this here.
    try:
        chosenFunction = functions.get(operation)
        # ... Etcera ...

Perhaps you have something wrong with identation, or py2exe do something odd here. 也许您的标识有问题,或者py2exe在这里做了一些奇怪的事情。 Make this change and let us know. 进行更改,然后告知我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM