Want to use Python to process the file, found that there is argv this usage, search to learn.
If you want to pass parameters to Python, then you need command line parameter support, so you can save every time to change the pace.
Usage is: Python xx.py xxx
Examples are as follows:
The results are as follows
The argv received here is a list variable
Let's say I read the file name here and start writing the open (argv, ' R '), which will prompt the type error and change to argv[1].
Here's a more detailed introduction to the following sys.argv[] usage
Sys.argv[] is used to get command line arguments, Sys.argv[0] represents the code itself file path, so the parameters starting from 1, the following two examples illustrate:
1, using a simple example of sys.argv[],
This example Os.system receive command line arguments, run parameter directives, save as sample1.py, command line with parameters run sample1.py Notepad, will open the Notepad program.
2, this example is a concise Python tutorial, understand it after you understand sys.argv[].
Save the program as sample.py. Let's verify that:
1) command line with parameters run: Sample.py–version output is: Version 1.2
2) command line with parameters run: Sample.py–help output is: This program prints files ...
3) in the same directory as sample.py, create a new a.txt Notepad file with the content: Test argv; command line with parameters run: sample.py a.txt, the output is a.txt file content: Test argv, here can also take a few more parameters, The program will output the contents of the parameter file successively.