A Simple question about a slice of a string.

Johann Hibschman johann at physics.berkeley.edu
Mon Jun 5 15:49:06 EDT 2000


Jay R Wren writes:

> I'm attempting to accomplish grabbing the last 6 characters of sys.argv[0]
> so that I can compare it to another string.
[snip]
> myprogname = sys.argv[0][ len(sys.argv[0])-10:len(sys.argv[0])

> it works like this, but I think there is a better, more proper way of doing
> it.  can someone let me know.  Thanks.

myprogname = sys.argv[0][-10:]

is equivalent.

-- 
Johann Hibschman                           johann at physics.berkeley.edu



More information about the Python-list mailing list