-1

Is it possible to manipulate a variable, for example:
file = "/Python/work.txt"
to just list work.txt, without /Python? excluding everything on the left of the "/"?

Thank you

Polymer
  • 1,108
  • 1
  • 9
  • 17
TheGarden
  • 43
  • 4
  • 1
    BTW, that's not valid Python syntax: you forgot the quotes. – PM 2Ring Nov 08 '17 at 13:12
  • Since you're using Python 3, I recommend that you become familiar with the awesome [`pathlib`](https://docs.python.org/3/library/pathlib.html) module, which is very handy for all sorts of path manipulation tasks. – PM 2Ring Nov 08 '17 at 13:17

1 Answers1

1

Of course! Simply do this:

file = "/Python/work.txt"
excluded = file.split("/")[-1]

This would return "work.txt" in the excluded variable.

Polymer
  • 1,108
  • 1
  • 9
  • 17