Matteo Secco Matteo Secco - 3 months ago 9
Python Question

How to create a file in a folder

How can i create a

.pck
file in a folder in Python?
The name of the folder is example
I tried:

file = open("\example\file.pck","wb")


But it says:


OSError: [Errno 22] Invalid argument: '\example\x0cile.pck'


EDIT:
Solved! The right command is:

file = open("example/file.pck", "wb")

Answer

You need to use forward slashes and also it seems that the example folder you trying to access doesn't exist. That's probably because you wanted to enter relative address but you entered an absolute one. So it should be:

open("example/file.pck", "wb")