Python help

Cole Tuininga colet at code-energy.com
Fri Feb 6 10:24:54 EST 2004


On Fri, 2004-02-06 at 09:12, Erik Price wrote:

> >> def main(args=sys.argv):
> >
> >One point about the above line - if you're testing from a python 
> prompt,
> >you'll need to pass your arguments in as a list.  So for instance,
> >>>> main( ["/etc/group"] )
> >
> >rather than just
> >
> >>>> main ( "/etc/group" )
> >
> >Otherwise, the next line would generate some rather peculiar behavior.
> >
> >>     f = file(args[1], "r")
> 
> Yes, exactly.  Although, I think you meant that the file name should 
> be in the second element of the list passed into the main() function, 
> because in "sys.argv" the first element (sys.argv[0]) is the script 
> name, and arguments start at sys.argv[1].

Oopsie - you are quite correct.  Good catch.

-- 
Brooks's Law: Adding manpower to a late software project makes it later.

Cole Tuininga
Lead Developer
Code Energy, Inc
colet at code-energy.com
PGP Key ID: 0x43E5755D





More information about the gnhlug-discuss mailing list