Code
import sys
def main()
print(sys.argv)
Version - 3.3
File name Pytest.py
running the file with syntax pytest.py aaa bbb ccc
But it didn't print anything and not giving any error also
You never call main().
Python has no special main function that is run automatically, so instead, you can place the code that you want to run when the file is called from the command line into a special if block:
import sys
def main():
print(sys.argv)
if __name__ == '__main__':
main()
To elaborate @Blender's answer: Python functions does not compile like in C. Functions are statements - they are being executed when the control encounters them, and it begins at the first line of the file.
The following code is perfectly legal:
# get b somehow
if b:
def foo(): return 1
else:
def foo(): return 2
print(foo())