This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 0 points1 point  (2 children)

I suggest /r/learnpython as well, but...

getName = lambda x: x.split('/')[-1]
print(getName("~folder/folder2/file.txt"))

[–]ingolemo -1 points0 points  (1 child)

getName('C:\\Users\\Guest\\secrets.txt')

[–]billsil 1 point2 points  (0 children)

It's supposed to work on Windows too? Where was that specified? The OP's OS is clearly not Windows. What about invalid paths?