Ask Your Question

How to short the string variable ?

asked 2012-11-01 13:45:24 -0500

Mongo gravatar image

updated 2012-11-01 16:51:29 -0500

JervisW gravatar image

Hi folks,

When I use this:

filename = os.path.basename(savecases)

I get something like "summer_light.sav"; the extension comes as well. Please, is there a python code to shorten it to "summer_light" only, I mean, to get rid of the extension ?

Thanks a lot, Andre

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-11-01 16:02:46 -0500

cajief gravatar image

There are a number of ways to do this in Python. One approach is to use "splitext" instead of "basename":

filename, extension = os.path.splitext(savecases)

or if you're only interested in the file name and not the extension...

filename = os.path.splitext(savecases)[0]
edit flag offensive delete link more


Thanks a lot Cajief, much much appreciated !

Mongo gravatar imageMongo ( 2012-11-03 09:41:12 -0500 )edit

answered 2012-11-03 09:40:23 -0500

Mongo gravatar image

Thanks Cajief, much much appreciated !!!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools


Asked: 2012-11-01 13:45:24 -0500

Seen: 150 times

Last updated: Nov 03 '12