I want to get the path to the currently executed script.I have used
os.path.realpath(__file__), however, it returns a string like D:\My Stuff\Python\my_script.py without proper backslash escaping! How to escape them?
path = "D:\My Stuff\Python\my_script.py"
escaped_path = path.replace("\\", "\\\\")
print(escaped_path)
Will output
D:\\My Stuff\\Python\\my_script.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With