Python COMMAND LINE PROCESSING
# Coding = UTF-8 ''' Lovely Python-3 pyday pycdc v0.3 @ see: http: ## www.woodpecker.org.cn?dive=python=scripts_and_streams=command_line_arguments.html ''' Import OS, sys Import Getopt # Import the getopt Module CDROM = ' # Media # cdrom0 ' Def Cdwalker (CDROM, cdcfile): Export = "" For Root, dirs, files In OS. Walk (CDROM): Export + = " \ N % s; % s " % (Root, dirs, files) # # The + = here does not actually use the join Method for High Efficiency Open (cdcfile, ' W ' ). Write (Export) # # Add 'w' to open and create a new one Def Usage (): Print ''' Pycdc usage: Python cdays-3-exercise-1.py-d cdc-K China fire # search for CD information in the CDC directory, find a file or directory with the words "China Fire", in which disk ''' Try : Opts, argS = Getopt. getopt (SYS. argv [1:], ' HD: e: K: ' )# # Do not add after H: because there are no other parameters Except Getopt. getopterror: usage () SYS. Exit () If Len (OPTs) = 0: usage () SYS. Exit () c_path = '' For Opt, ARG In Opts: # # Arg is read from this opts and does not understand the usefulness of The args above If OPT In ( ' -H ' , ' -- Help ' ): Usage () SYS. Exit () Elif Opt = ' -E ' : # Identifies whether SYS. argv [2] has a directory for automatic creation. # Cdwalker (CDROM, ARG) Print " Record the disc information to % s " % ARG Elif Opt = ' -D ' : C_path = ARG Elif Opt = ' -K ' : If Not C_path: # # The following command is run when c_path is '', that is, it is not assigned a value. Usage () SYS. Exit () # Search for files
End