-1

This is the first line of my program:

def main():
    country = input('\nPlease enter the country>   ')

I selected the python Build, and when I click Ctrl-B it compiles fine, and tells me how long it took. Why doesn't it print the line and ask me for input?

0

3 Answers 3

2

You have to call the main function/the notation you're liking looking for is

if __name__ == '__main__':
    country = input('\nPlease enter the country>   ')
Sign up to request clarification or add additional context in comments.

Comments

1

I am assuming you haven't called the function main anywhere in your code. You can solve this by adding if __name__ == '__main__': main() at the end of your code.

5 Comments

Well that's embarrassing... So now it says "EOFError: EOF when reading a line" after running. Am I supposed to make an input file? I thought I would be able to enter text after the prompt.
Does sublime give you the chance to put in an input when your program asks? Or does your program just run and then crash?
This it what it outputs (so I guess it crashes because there is no input?): Please enter the country> Traceback (most recent call last): File "/Users/xxxx/Desktop/Github/Country_Capital.py", line 14, in <module> country = input('\nPlease enter the country> ') EOFError: EOF when reading a line [Finished in 1.3s with exit code 1]
I'm guessing sublime is killing your program before you are able to input anything causing the traceback. I would suggest running the script manually with python Country_Capital.py
Just did some more googling and apparently "you cannot interact with programs that are run within Sublime, regardless of the language." Oops. Thanks for pointing out the missing call though!
0

you should be using sublime-repl. to install it you need package control available here. Then open sublime text.type ctrl-shift-p ,choose sublime-repl-python this will run an interpreter in sublime text. import the file where you defined the module(eg.test.py). and then call test.main()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.