[Tutor] Fw: Command line args
ALAN GAULD
alan.gauld at btinternet.com
Tue Apr 10 20:04:18 CEST 2007
Please use REPLY ALL to include the rest of the group.
The code looks OK although the error that you raise should probably
be a RuntimeError rather than a SyntaxError since its not really a
syntax problem.
You can get a list of the built in exceptions by doing:
>>> import exceptions
>>> dir(exceptions)
HTH,
Alan G.
----- Original Message ----
From: Teresa Stanton <tms43 at clearwire.net>
To: Alan Gauld <alan.gauld at btinternet.com>
Sent: Tuesday, 10 April, 2007 5:52:44 PM
Subject: RE: [Tutor] Command line args
This is how I actually did it after reading a number of your posts:
numLst = [] #an empty list
if len(sys.argv) == 2: #only one filename, please
infile = open(sys.argv[1], 'r')
elif len(sys.argv) < 2: #handles the case where no file is provided on
command line
infilename = raw_input("Name of file: ")
elif len(sys.argv) > 2: #raises error if more than one filename is provided
raise SyntaxError, "Too many arguments"
data = open(infilename, 'r')
for x in data:
numLst.append(x.strip('\n').split(" "))
Thank you so much for the discussion. It has been very helpful!
___________________________________________________________
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html
___________________________________________________________
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html
More information about the Tutor
mailing list