Python Compile file(.pyc) generated even after errors in code-why?
<p>I have the below code in a file <strong>a1.py</strong></p>

<pre><code>fff
def test(arg):
        print 'sid'
        print arg
        print 'sid2'
test()
</code></pre>

<p>The above code contains 2 errors:</p>

<ol>
<li><p>fff does not exist and is still being asked to print</p></li>
<li><p>Arguments are not passed in test()</p></li>
</ol>

<p>Now i write an another file <strong>b1.py</strong>
In that file the code is:</p>

<pre><code>import a1
print 'b1 execution done'
</code></pre>

<p>Que 1: I executed b1.py and a1.pyc file is generated. Why ? There is a syntax error.pyc file should not have been generated?</p>

<p>Que2: Explain in laymen terms what is pyc file and what role does it play?</p>

<p>Que3: Why is pyc file generated even if a1.py has errors ?(e.g. argument not being passed)</p>

<p>Python automatically compiles your script to compiled code, so called byte code, before running it. When a module is imported for the first time, or when the source is more recent than the current compiled file, a .pyc file containing the compiled code will usually be created in the same directory as the .py file.</p>

python python-2.7 compilation