[Tutor] sys.argv[1: ] help

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sat Feb 26 00:57:24 CET 2005



> > I am reading ' Learning Python second edition' by Mark Lutz and David
> > Ascher, and I trying the code examples as I go along. However I am
> > having a problem with the following, which I don't seem to be able to
> > resolve :-

> > # test.py
> > import sys
> >
> > print sys[ 1: ]
> >
> > This I believe is supposed to print the 1st argument passed to the
> > program. However if I try
> >
> > test.py fred
> >
> > All I get at the command line is
> >
> > []


Hi Jay,

Are you sure that is what your program contained?  I'm surprised that this
didn't error out!  The program:

######
import sys
print sys[1:]
######

should raise a TypeError because 'sys' is a module, and not a list of
elements, and modules don't support slicing.  Just out of curiosity, can
you confirm that you aren't getting an error message?



(I know I'm being a bit silly about asking about what looks like a simple
email typo, but computer programming bugs are all-too-often about typos.
*grin*

When you write about a program, try using cut-and-paste to ensure that the
program that you're running is the same as the program you're showing us.)


Best of wishes to you!



More information about the Tutor mailing list