how to pass arguments to python script

if you want to pass arguments to script, you will be able to do it with this page.

python script can get arguments from interpreter.

but, in order to do it, you need built-in module "sys"
"sys" has "argv" attribute. so, interpreter pass the arguments to "argv" attribute of "sys".

let's try it.

in order to get arguments, I created a script "main.py". and I coded like below.

1
2
3
4
import sys
print(sys.argv)
cs

as you can see, I imported "sys" and I printed out "argv" of "sys".
in detail, "argv" is list data type. and in order to use attribute of any module, dot(.) has to be used between module name and attribute name.

and then, I executed the script with some arguments.


as you see above screen, the first argument is file name. and arguments the are passed from interpreter are begining from the second of list.


Comments

Popular posts from this blog

making menubar and menu on QML

let's start QML programming with PySide2

QSizePolicy Fixed example in pyside2