I have problem with refering to special symbol in string:
I have: path='C:\dir\dir1\dir2\filename.doc'
and I want filename.
When I try: filename=path[path.rfind("\"):-4]
then interpreter says it’s an error line right from “\” since is treated as a comment.
You can use
"\\", technically it would be better to useos.path.sepif you insist on using backslashes. But better yet, use/in your paths, it works fine on WindowsPython has builtin functions to manipulate paths. Note that you need to double the backslashes if you still prefer them to forwardslashes
and using forwardslashes