I have some problems in the ex13 in the lp3thw


#1

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.


#2

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.


#3

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.


#4

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


#5

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.