[Python-ideas] Getting file name of Path without suffix

Antoine Pitrou solipsis at pitrou.net
Mon Jan 6 14:46:05 CET 2014


On Mon, 6 Jan 2014 05:28:48 -0800 (PST)
Ram Rachum <ram.rachum at gmail.com> wrote:

> Hi guys,
> 
> What do you think about introducing this Path property:
>      
>     @property
>     def suffixless_name(self):
>         return self.name[:-len(self.suffix)] if self.suffix else self.name
> 
> It's simple but I'd really hate to have this conditional slicing in user 
> code.

Have you tried .stem?
http://docs.python.org/dev/library/pathlib.html#pathlib.PurePath.stem

Regards

Antoine.




More information about the Python-ideas mailing list