[lug] Python Compiler Question

Ian S. Nelson nelson_ at attglobal.net
Tue Apr 18 17:48:11 MDT 2000


I believe that python automatically bytecode compiles when you import.

you could do something like
import yourprogram

yourprogram.run()

and that should do it.

There is also the py_compile module

py_compile.compile('yourcode.py', 'yourbytecode.pyc')


Ian Nelson



Wayde Allen wrote:

> I recently wrote a short Python program that seems to run OK, but what is
> interesting is that I don't seem to be getting the byte compiled version
> of the program after running it once.  In other words, I've got this
> program opencalc.py and after running it I don't get an opencalc.pyc
> version.  I was thinking that this should always happen.  What gives?
>
> The code is quite short and simple:
>
> #!/usr/bin/env python
>
> # George Free's Open Circuit model
>
> from math import sqrt, pow, atan2
>
> startfreq = 0.001
> endfreq   = 1.001
>
> freq = startfreq
>
> Copen = 2e-13
> PI    = 3.1415926
>
> print "#Open Circuit model used by George Free"
> print "#"
> print "# Freq, Magnitude, Phase"
>
> while freq <= endfreq:
>    Yopen=complex(0,2 * PI * freq * 1e9 * Copen)
>    Opcalc = (1.0 - 50 * Yopen) / (1.0 + 50 * Yopen)
>
>    Magnitude = abs(Opcalc)
>    Phase     = atan2(Opcalc.imag, Opcalc.real) * (360 / (2*PI))
>
>    print freq, Magnitude, Phase
>
>    freq = freq + 0.001
>
> - Wayde
>   (wallen at boulder.nist.gov)
>
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug






More information about the LUG mailing list