Executing Python Script From Command Line is Hiding Print Statements

printing, python, terminal

Solution

Add at the end of the file:

if __name__ == '__main__':
    hello()

Problem

I know this must be a super basic question, however, I have tried finding a simple answer throughout SO and cannot find one. So my question is this: How can I execute a python script from the command line such that I can see print statements. For example, say I have the file test.py: ``` def hello(): print "hello" ``` If I enter the interpreter, import test.py, and then call test.hello(), everything works fine. However, I want to be able to just run ``` python test.py ``` from the command line and have it print "hello" to the terminal. How do I do this? Thanks! UPDATED: Yes, sorry, my script is actually more like this: ``` def main(): hello() def hello(): print "hello" ``` Do I still need to call main(), or is it automatically invoked?

Original source

Related problems