Python script automatically generates required files
In the work we often need to write another file through a file, but since it is the corresponding relationship can certainly summarize the rules for the computer to help us to complete, today we have a generic file generated by the Python script to achieve this function, we will be free from the daily duplication of labor!
Define a function
def PRODUCEBNF (infilename,outfilename): list=[] with open (Infilename, ' R ') as INF: for line in Inf.readlines (): list.append (Re.match ("Regular expression"). Group (?)) With open (Outfilename, ' W ') as Outf: i=0 outf.write ("File header"); For command in List: outf.write ("Write to the content you just read (and possibly a corresponding relationship)") Outf.write ("write Something Else") outf.write ("Write file Footer")
Almost, in most cases, this is the framework, this function requires an input file, an output file, in general, we want to be able to import the input file parameters from the command line, and then generate output files in this directory
Get Input/output path
INFILE=SYS.ARGV[1]PRODUCEBNF (Infile,os.path.join (Os.path.dirname (infile), "name of the output file"));
OK, get it done, and then on the command line we execute the Python script and then add a parameter to complete it.
The script is used to help us simplify the repetitive work, let us do more meaningful, more need to think about things, so we hope that we will be more in the future with the script to simplify their repetitive work.
Thank you for reading, hope to help everyone, thank you for the support of this site!