[Tutor] getting filen basename without extension

Timmie timmichelsen at gmx-topmail.de
Thu Jan 10 14:33:01 CET 2008


> > What I found is this:
> > import os
> > myfile_name_with_path = 'path/to/my/testfile.txt'
> > basename = os.path.basename(myfile_with_path)
> > filename = os.path.splitext(basename)
> > myfile_name_without_suffix = filename[0]
> 
> The last two can be easily combined as:
> 
> > myfile_name_without_suffix = os.path.splitext(basename)[0]
> 
> But otherwise you are using the "correct" mechanism if 
> you want a reliable result.
Thanks for this confirmation.

I am happy to have made some tiny progress in my python learings...

Kind regards,
Timmie



More information about the Tutor mailing list