Ask Your Question
1

How to short the string variable ?

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

Mongo gravatar image

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

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
2

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

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

Comments

Thanks a lot Cajief, much much appreciated !

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

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

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

Stats

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

Seen: 342 times

Last updated: Nov 03 '12