0

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.

Łukasz Szcześniak
  • 1,417
  • 11
  • 23

1 Answers1

1

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.

Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60
  • They are all in the same module. I just didn't copy them to evade long-code spam. – Łukasz Szcześniak Jul 29 '14 at 21:20
  • Answer adited with another idea. – Raydel Miranda Jul 30 '14 at 12:08
  • Thanks for your reply. Actually it changed something - now it always throws NameError, that function doesn't exist. I also added print operation and data is passed right, just as inputted. Also I tried if operation == '1': print 'works' before last line in try column and it also worked fine. So the problem is in ***print ("Result of your conversion is {num}".format(num = chosenFunction(get_float(), turn)))*** because it somehow always throws error. – Łukasz Szcześniak Jul 31 '14 at 09:19
  • Ok, but that's not the original question, please mark this as answered. I'll be glad to help you if you post another question. – Raydel Miranda Jul 31 '14 at 12:33