[Tutor] Read from large text file, parse, find string, print string + line number to second text file.
Steven D'Aprano
steve at pearwood.info
Sat Feb 2 08:54:33 CET 2013
On 02/02/13 15:31, Scurvy Scott wrote:
> One question related to the instruction aspect- does this make sense to you?
>
> If len(sys.argv) == 0:
> print "usage: etc etc etc"
Right idea, but not quite correct.
sys.argv always includes at least one item, the name of the script being called. This is why you will often see code like this, to extract the actual arguments:
argv = sys.argv[1:] # slice excluding the first item
if len(argv) == 0:
usage()
else:
main(argv)
or similar.
--
Steven
More information about the Tutor
mailing list