Suppose we have
mystr = 'hello.py'
mystr = 'hello'
if not 'py' in mystr.rsplit('.')[1]:
The first case is fine, but the second case results in an “out of range” error.
Goal:
If .py exists in the string, do nothing. If .py is not part of the filename, do XYZ.
Note : The user input may or may not have a .’extension-type’.
Attempt:
Either check the length, or convert the list into a string.
Any alternative? I am not sure if this is too localized. Just wondering.
Thanks.
I’d simply write
(Assuming, of course, that I’ve understood your intent.)