Hi everyone and happy christmas.
IN THE LEARN PYTHON 3 THE HARD WAY I FOUND ARGV,MODULE,FEATURES AND ARGUMENT.BUT I AM NOT UNDERSTANDING WHAT THEY ARE AND WHAT THEY DOES.ANYONE PLEASE EXPLAIN THESE TOPICS.
THANKS IN ADVANCE.
Hi everyone and happy christmas.
IN THE LEARN PYTHON 3 THE HARD WAY I FOUND ARGV,MODULE,FEATURES AND ARGUMENT.BUT I AM NOT UNDERSTANDING WHAT THEY ARE AND WHAT THEY DOES.ANYONE PLEASE EXPLAIN THESE TOPICS.
THANKS IN ADVANCE.
Keep working through the exercises as you use them a few times so they may start to make sense.
In essence, argv is a system module that lets you enter arguments directly to the command line. You can then used the arguments in your script.
So if you had a HelloWorld.py file, like this:
print(âHello Worldâ)
You could perhaps capture a name on the command line and replace âWorldâ with that.
from sys import argv
script, name = argv
print(fâHello {name}â)
In this example you are importing the module so you can use it in your file, then telling python that on the command line, the first argument will be your script, and the second is to be assigned to a variable called ânameâ. You can then add that variable into the f-string.
python HelloWorld.py Towhid
So you are telling the computer to run Python, then run the script (HelloWorld.py - hence the âscriptâ assignment) and then use the argument âTowhidâ that you have mapped to a variable called ânameâ.
The output should be displayed as:
Hello Towhid
Every time you use the command line or Terminal, you are using arguments that have an impact on a script or module. In these examples, you are just defining you own simple example.
HTH.
Now I understand what is an argument and what is argv.But I donât know what is module and features.
Thanks for your reply.
Just keep working through the book. Scribble down on a pad somewhere that you need to know about modules and functions. And when you come across then later in the book, make notes against them or cross them out when you know enough.
If you are too eager, perhaps take a look at the Python Docs. It sometimes helps, but assumes a certain level of known. https://docs.python.org/3.6/tutorial/modules.html
Yep, as @gpkesley when you run into something you donât know, write it down and then keep moving or research it online. You donât learn a concept in 1 exercise, you learn it in about 3-5 exercises. So donât let hitting an unknown concept stop you.