#!/usr/bin/python
import sys, getopt
def Usage ():
print "ftp [-c][-h]"
sys.exit(0)
try:
optlist, list = getopt.getopt(sys.argv[1:],
’:ch’)
except getopt.GetoptError:
Usage()
sys.exit(2)
for opt in optlist:
print opt
if opt[0] == ’-h’:
Usage()
if opt[0] == ’-c’:
print "c option found"
>>> import getopt >>> args = ’-a -b -cfoo -d bar a1 a2’.split() >>> args [’-a’, ’-b’, ’-cfoo’, ’-d’, ’bar’, ’a1’, ’a2’] >>> optlist, args = getopt.getopt(args, ’abc:d:’) >>> optlist [(’-a’, ’’), (’-b’, ’’), (’-c’, ’foo’), \ (’-d’, ’bar’)] >>> args [’a1’, ’a2’]
>>> s = ’--condition=foo --testing --output-file \
abc.def -x a1 a2’
>>> args = s.split()
>>> args
[’--condition=foo’, ’--testing’, ’--output-file’,
’abc.def’, ’-x’, ’a1’, ’a2’]
>>> optlist, args = getopt.getopt(args, ’x’, [
... ’condition=’, ’output-file=’, ’testing’])
>>> optlist
[(’--condition’, ’foo’), (’--testing’, ’’),
(’--output-file’, ’abc.def’), (’-x’, ’’)]
>>> args
[’a1’, ’a2’]
#!/usr/bin/python
from sys import argv
def scanner(name, function):
file = open(name, ’r’)
line = file.readline()
while line:
function(line)
line = file.readline()
file.close()
def processLine(line):
print line
filename = ’ftplog.data’
scanner(filename, processLine)
Mon Nov 18 17:38:24 2002 1 \ g410-helpdesk.isd.glam.ac.uk 51200 \ /user/ftp/pub/m2/osi/lab1.tar b _ o a \ IEUser@ ftp 0 * c
#!/usr/bin/python
import string
def processLine(line):
words=string.split(line)
print "date = ", words[:5]
print "machine = ", words[-7]
print "file = ", words[-5]
processLine("Mon Nov 18 17:38:24 2002 1 \
g410-helpdesk.isd.glam.ac.uk \
51200 \
/user/ftp/pub/m2/osi/lab1.tar \
b _ o a")
This document was produced using groff-1.19.