SyntaxFix
Write A Post
Hire A Developer
Questions
I prefer the following one-liner approach using str.rsplit():
my_filename.rsplit('.', 1)[0] + '.jpg'
Example:
>>> my_filename = '/home/user/somefile.txt' >>> my_filename.rsplit('.', 1) >>> ['/home/user/somefile', 'txt']