Danny Yoo wrote:
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!
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Hi,
Sorry for the late response, I tried all of the the suggestions, including correcting my typo of print sys[1:] and tried print sys,argv[1:], this does now work as long as I run 'python test.py fred joe' it returns all the arguments. If I try just test.py all I get is '[]' . Is there something wrong with my environmental variables in Windows XP, I would like to be able to just use the file name rather than having to type python each time. Any help would be gratefully received.
Richard G. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor