Recent Posts

learn python interpreter argument



Hello this is Juny.

python has interpreter instead of compiler
we can execute python script and any other special command by interpreter.


I will not handle everything of python interpreter.
I will handle most important thing of that.

if you need more information about that, check official python reference homepage.

invoke interpreter


we can invoke python interpreter by launcher.
there is launcher in the location that python is installed in

there are 2 ways to execute launcher.

first one, directly executing python.exe in the installed location.




run_python_interpreter_location




second one, executing python.exe as command in Windows command prompt.




run_python_interpreter_command



if you have already set the environment path, you can execute it by "python" keyword.




run_python_interpreter_command_environment



exit interpreter


if you want to exit interactive interpreter, input the end of file(EOF).
end of file (EOF) is Ctrl+Z in Windows.




exit_python_interpreter




interactive mode


if you execute launcher without any command option,
interpreter will be invoked in interactive mode.
interactive interpreter get any command by standard input.
if EOF is input, it exit.



non-interactive mode


we can enter the non-interactive mode by three ways.


  • first, with -c command option.
  • second, with -m command option.
  • third, with script command option.

if non-interactive mode, they are parsed before executed.



we will see only script command in this post.

there are 2 ways to execute python script.


  • first, directly double click python script file in Windows explore.
  • second, execute launcher with script option in Windows command prompt.


you have to put the full path or relative path of script in command.


python script




run_script_python

run_script_python2



interpreter arguments


we can pass the arguments to python interpreter.
they are passed by command options.

python [args]


sys is python module.
argv variable in sys save the arguments that are passed.

for example,
we can do it like "python script a b c d e" in non-interactive interpreter mode.
we can also do it like "python - a b c d" in interactive interpreter mode.
each argument is saved in element of argv.
like "argv[0] = script name(first one), argv[1] = a(second one)"



interpreter_arguments


general options


when you type "--help" as option, you can see the manual of command options.



python_command_help




when you type "--version" as option, you can see the version of python.




python_command_version



help function


interpreter has help function.
if you call the function, you can see the manual of lexical keywords.

when you call the function, the prompt is changed from ">>>" to "help>"
you can type any keyword in that.





interpreter_help_function






learn python interpreter argument learn python interpreter argument Reviewed by Juny on 7월 03, 2019 Rating: 5

댓글 없음:

Powered by Blogger.