2

I have python code that works in command prompt(Windows) using python file.py command, but when I copy this code and put it inside server, it does not work. (it gives me an error which does not occur when executed in command prompt)

Both Windows and server(ubuntu; it uses django as framework) use same version of Python - 3.5.2

Any advice or suggestion would be appreciated. Thank you in advance.

Here is the part of the code which gives me error (local variable 'district' referenced before assignment) only on server.

def GetDistrict_driver(addr): district = '' if addr == 'Seoul': district = 'S1' elif addr == 'Incheon': district = 'A1' elif addr == 'Daejeon': district = 'B1' elif addr == 'Gwangju': district = 'C1' elif addr == 'Daegu': district = 'D1' elif addr == 'Ulsan': district = 'E1' elif addr == 'Busan': district = 'F1' return district 

Error from server enter image description here

6
  • 2
    are you sure both files are identical. Because based on the fragment, that's impossible. How did you transfer your file to the server? Did you inspect that nothing went wrong during transferring the file? Commented May 10, 2017 at 10:41
  • @WillemVanOnsem Yes. I made sure the files are identical over and over again. I have transfered the file via git using push and pull. Commented May 10, 2017 at 10:42
  • I can't see how the error arises from this code, my guess is that 1 version has a typo in the return district line or there is more relevant code you don't show Commented May 10, 2017 at 10:43
  • At which line is this error reported? Commented May 10, 2017 at 10:47
  • 1
    What kind of newlines do you use? maybe put print(locals()) before return and see what's in the function scope. Commented May 10, 2017 at 10:54

1 Answer 1

1

For the server try this command:

python3 file.py 

Edited: In some linux based os there is difference calling python scripts with "python" and "python3" - first one calls the python2.7 interpreter and the second one - python 3 interpreter.

Sign up to request clarification or add additional context in comments.

3 Comments

First, that is not always true, python may be an alias for python3 and second, that would not explain the error anyway
@stefan.stt I have edited my post which shows that it is using 3.5.2.
@smchae ok, I will try to think of another possible reason.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.