How to Create a file at a specific path in python?
<p>I am writing below code which is not working:</p>

<pre><code>cwd = os.getcwd()
print (cwd)
log = path.join(cwd,'log.out')
os.chdir(cwd) and  Path(log.out).touch() and os.chmod(log.out, 777)
</code></pre>

<p>how can I create a log.out into cwd ?</p>

<p>To create an empty file:</p>

<pre><code>import os

cwd = os.getcwd()
os.chdir(cwd)
filename = 'log.out' 
with open(os.path.join(cwd, filename), 'wb') as f:
    f.write('')
os.chmod(filename, 777) 
</code></pre>

<p>This will create an empty file called <code>log.out</code>, which of course will be content-empty, but that can easily change with the use of the <code>f.write(content)</code> function.</p>

python