Let's open up your "Hello" program to communicate with the outer World.
- Call programs from command line with arguments.
- Import a built-in module.
- Handle list contents.
- Modify
hello.py
to greet the name or names given after the name of the script at the prompt. Running the script with no arguments still prints"Hello, World!"
- Running
python3 hello.py Joe
writes"Hello, Joe!"
to the console. - Running
python3 hello.py Cotton Eye Joe
writes"Hello, Cotton Eye Joe!"
. - Running
python3 hello.py
writesHello, World!
to the console.
- Running
None
- Python gives access to the command line arguments through the built-in
sys.argv
list (see the first linked background material). Use indexing, slicing, and joining to access and effectively manipulate the contents of this list (see the other two linked materials).