Rhonda Rhonda - 5 months ago 17
Python Question

Python doesn't create file if not existing

I cannot figure out how to create file that does not exist. I tried following, yet I get error that file does not exist.

Please guide.

f=open('c:\Lets_Create_Malware\output.txt', 'r+')

f=open('c:\Lets_Create_Malware\output.txt', 'w+')

f=open('c:\Lets_Create_Malware\output.txt', 'a+')

f=open('c:\Lets_Create_Malware\output.txt', 'r')

f=open('c:\Lets_Create_Malware\output.txt', 'w')

f=open('c:\Lets_Create_Malware\output.txt', 'a')

Answer

Use a double backslash:

f=open('c:\\Lets_Create_Malware\\output.txt', 'w+')

From the docs:

The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.