A Simple question about a slice of a string.

andres at corrada.com andres at corrada.com
Mon Jun 5 20:19:16 EDT 2000


On Fri, Jun 02, 2000 at 05:12:29PM -0400, Jay R. Wren wrote:
> I'm attempting to accomplish grabbing the last 6 characters of sys.argv[0]
> so that I can compare it to another string.
> If 'myprog' is called as /usr/local/bin/myprog.  It could be called from any
> path, as long as the 'myprog' portion is there, certain things will
> execute.(this is used as a symlink)
> 
> 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.
> 
> -Jay
> 

I don't understand exactly what you want but if what you want to extract
"myprog" from whatever path you are given you could use the module os.path
to do so as follows:

os.path.basename( '/usr/local/bin/myprog' )

------------------------------------------------------
Andres Corrada-Emmanuel   Email: andres at corrada.com
------------------------------------------------------




More information about the Python-list mailing list