3

I made a file named "Main" in pydev and inside it wrote:

if  __name__ =='__Main__':
    main()

def main():
    print("jargon")    

It says my call to main() under the if statement contains an undefined variable and won't compile. Why does it do this?

1 Answer 1

9

Python code is executed top-to-bottom. You need to move your main() definition above the if __name__ == '__main__' block. The way you have it, at the time that you try to call main(), the function does not yet exist.

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

2 Comments

I see. Since Java is bottom-up would a Jython interpreter execute bottom-up or top-bottom?
It will still be top down, since Jython code is Python source, not Java, so it follows the rules of the Python language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.