简体   繁体   中英

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.

When I converted it to .exe with py2exe it asks me to input number of function in my mind but it doesn't work. After putting number (for ex. 1) it asks me for a number again.

What's wrong with this code? Thanks for help.

I suppose those functions are defined in another python module. And you missed that writting your setup.py file.

You have to add all python modules/packages to the setup.py .

Edit

Just a feeling but, Could you add an else statement after the break ?

 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. Make this change and let us know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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