How to create a file in a folder
<p>How can i create a <code>.pck</code> file in a folder in Python?
The name of the folder is example
I tried:</p>

<pre><code>file = open("\example\file.pck","wb")
</code></pre>

<p>But it says: </p>

<blockquote>
  <p>OSError: [Errno 22] Invalid argument: '\example\x0cile.pck'</p>
</blockquote>

<p>EDIT:
Solved! The right command is:<code>
file = open("example/file.pck", "wb")</code></p>

<p>Paths can be tricky, especially if you want to run your code on Unix-based and Windows systems. You can avoid many problems by using <code>os.path</code> which generates paths that will work on any os. </p>

<p>To open a new file use the 'w+' option instead of 'rw'.</p>

<p>In your case:</p>

<pre><code>import os
file_path = os.path.join(os.path.curdir, 'file.pck')
file = open(file_path,'w+')
</code></pre>

python