user3763437
user3763437

Reputation: 359

Simple Python program with arguments not working

Just learning Python and spent quite some time on this. Why isn't it outputting anything when I pass arguments like this:

python new2.py Alice

Source code:

#!/usr/bin/python

import sys

def Hello(name):
    if name == 'Alice' or name == 'Nick':
       name = name + '!!!'
    else:
       name = name + '???'
    print 'Hello', name

def main():
    Hello(sys.argv[1])

Upvotes: 0

Views: 83

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375494

Python doesn't implicitly call your main function. You either call it directly:

def main():
    Hello(sys.argv[1])

main()

or you wrap it in an idiomatic clause to do a similar thing:

if __name__ == "__main__":
    main()

Upvotes: 4

Related Questions