Detailed explanation of the problems encountered when exploring sys. argv in python

  • 2021-09-11 20:35:11
  • OfStack

Automated task

This is a note about the problems I encountered in learning python automation office.

About reading and writing articles

The book I used is "python Programming Quick Getting Started", and I encountered difficulties in understanding Chapter 8. The main problem is that there are obstacles in understanding when contacting sys. argv and creating bat files.

sys. argv This function is one of the most commonly used functions in writing python scripts.

sys is a "standard library" of Python, that is, the official "module", which is the abbreviation of "System" and encapsulates some system information and interfaces.

Official document reference: https://docs.python.org/2/library/sys.html

Chinese version document reference: http://xukaizijian.blog.163. com/blog/static/170433119201111625428624/

sys.argv

1. First, for sys. argv

This function does not specifically explain its function in the book, so I searched the data and learned: "sys. argv [] is a bridge to get parameters from outside the program. This" outside "is very critical, so those who try to explain its function from the code have not understood it."

What I don't understand about this function is mainly 1: What is the specific way in which it bridges external parameters? 2: sys. argv [0] returns a path, so when did sys. argv [1] come in and out of sys. argv?

Therefore, the experiment was carried out with reference to other blog for these two problems, and it was found that the bridge was built in the interactive window of Windows. The specific way was to put a parameter after the program you entered to run, and this parameter was saved in sys. argv [1], so all 12 questions are actually one problem.

Create a batch file

It should be that I am completely a white, just contacted python for a short time, and I don't have any cs foundation, so I met a lot of knowledge I don't understand here.
There are many problems encountered here, but only one problem in the end, which is actually the importance of escape characters to these commands.


@py.exe E:\\pythonScript\\file\\pw.py %*
@pause

What I saw on the Internet before was:


@py.exe E:\pythonScript\file\pw.py %*
@pause

However, I didn't know that this instruction in the batch file still needed an escape character, so it didn't work properly. Finally, there is no other way, only the last idea is left in my mind, so I added an escape character, and finally I succeeded by entering pw email after Windows+r.

Summarize


Related articles: