Du bist hier: Snippet-Verzeichnis » Python (121)
Sprache:

clargs.py

Sprache: English
Programmiersprache: Python
Veröffentlicht von: inkedmn [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1053


Beschreibung

Lists and sorts command line arguments, as well as searches for and identifies a pre-determined 'match' variable.

Code

1 #!/usr/bin/env python 2 # List and sort Command line Arguments, and testing for match variable 3 4 import sys #import sys module 5 6 if len(sys.argv) < 2: #gives error if less than two arguments (counting filename) 7 print "No command line arguments to list" 8 else: 9 sys.argv.sort #sort list alphabetically 10 match == 'linux' #define 'match' variable 11 for i in range(1,len(sys.argv)): #create range of arguments minus filename itself 12 if sys.argv[i] == match: #is the match variable one of the args? 13 print sys.argv[i], "MATCH" #print sorted list with MATCH next to match variable 14 else: 15 print sys.argv[i] #print sorted list of args 16

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS