Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't my python code print anything?

Tags:

python

A program I wrote wasn't printing anything when I executed it out of the terminal, so I tried the ran the following code

import sys

#!/usr/bin/python

def main(argv):
    print  "hell0\n"
    sys.stdout.flush()

this is the terminal why is it not printing out hello. Is the main function even running?

like image 401
dcousina Avatar asked Dec 11 '22 19:12

dcousina


2 Answers

Python does not automatically call main() (and you'll need to use the sys library to get argv).

#!/usr/bin/python

import sys

def main():
    print  "hell0\n"

main()
like image 106
personjerry Avatar answered Jan 03 '23 14:01

personjerry


You didn't call main anywhere, you've only defined it.

like image 40
wim Avatar answered Jan 03 '23 16:01

wim