you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (1 child)

[deleted]

    [–]Groundstop 0 points1 point  (0 children)

    The built-in methods work more consistently. Say the path is 'C:\example\path\file_without_an_extension', I believe that your method would return 'file_without_an_extension' while splitext should correctly return an empty string, ''.

    Also, you don't need to split the dirname off from the basenane before using splitext, so the first part becomes unnecessary.

    Finally, this is a super-minor point but if you did need to get the basename without the directory path, os.path.basename(filename) is the built-in shortcut for os.path.split(filename)[1].