I'm trying to write only a file name to a .txt file, however, the entire file path is being written i.e. C:\Users\OneDrive\a.png
I only want a.png to be written. I know I can slice a string in python like this:
a="abcdefg"
print(a[2:4])
cd
but how do I do this at a fixed point in a string?
The file path will always remain static although the file name and length itself will change.
cddoesn't even make sense in that context. If possible, use Python 3! Concerning string operations, just check out the documentation on the Python website to see if there's anything useful. Alternatively, runhelp(string)in an interactive session to retrieve some infos on thestringtype (unicodein version 3). Also, there are special path-handling methods to work with paths, which are better suited to this case.afrom the example.