Why can’t I print to terminal with my python script?

Firstly, please ask programming questions on Stackoverflow unless they are specific to Unix/Linux shell programming.

Python doesn’t execute main (or any other) function by default.
You can either just do:

#!/usr/bin/env python3
import sys
sys.stdout.write("Hello")

or if you want to keep the function, but call it when the script is run:

#!/usr/bin/env python3
import sys

def main():
    sys.stdout.write("Hello")

if __name__ == '__main__':
    main()

The second method should be used if you are going to import the script into some other file, but otherwise, use the first one.

Also, you can just use the Python print function, which writes to stdout by default.

#!/usr/bin/env python3
print("Hello")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)