How to use *.py modules instead of *.pyc?

Discussion in 'Python' started by dsblizzard@gmail.com, Jan 19, 2009.

  1. Guest

    How to use *.py modules instead of *.pyc or automatically recompile
    all modules each time I change *.py files?
    Thank you in advance.
    , Jan 19, 2009
    #1
    1. Advertising

  2. Chris Rebert Guest

    On Sun, Jan 18, 2009 at 5:13 PM, <> wrote:
    > How to use *.py modules instead of *.pyc or automatically recompile
    > all modules each time I change *.py files?


    IIRC, you shouldn't need to worry about this. Python checks the
    modification times on the .py and .pyc files and if the .pyc is older,
    it regenerates the .pyc from the .py; thus ensuring that the latest
    version of the source file is always used.
    What led you to conclude otherwise?

    Cheers,
    Chris

    --
    Follow the path of the Iguana...
    http://rebertia.com
    Chris Rebert, Jan 19, 2009
    #2
    1. Advertising

  3. John Machin Guest

    On Jan 19, 12:13 pm, wrote:
    > How to use *.py modules instead of *.pyc or automatically recompile
    > all modules each time I change *.py files?


    You don't need to do anything special. If, when you import foo,
    foo.pyc is outdated by changes to the foo.py that is in the same
    directory, then foo.py will be compiled to a new foo.pyc -- otherwise
    compilation is unnecessary and the existing foo.pyc will be used.

    If you think you have a problem, it could be caused by foo.pyc being
    in a directory that is in sys.path but you are editing a foo.py that
    is not in sys.path.

    HTH,
    John
    John Machin, Jan 19, 2009
    #3
  4. Chris Rebert Guest

    On Sun, Jan 18, 2009 at 5:13 PM, <> wrote:
    > How to use *.py modules instead of *.pyc or automatically recompile
    > all modules each time I change *.py files?
    > Thank you in advance.


    Also, just for the sake of completeness (since John and I have shown
    that your real problem lies elsewhere), I happened to come across the
    `compileall` module via a Planet Python blog, which mass-compiles
    ..py-s into .pyc-s:

    http://blog.doughellmann.com/2009/01/pymotw-compileall.html

    Cheers,
    Chris

    --
    Follow the path of the Iguana...
    http://rebertia.com
    Chris Rebert, Jan 19, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anastasios Hatzis

    Out-dated compiled modules (*.pyc)?

    Anastasios Hatzis, Aug 26, 2006, in forum: Python
    Replies:
    3
    Views:
    553
    Cliff Wells
    Aug 26, 2006
  2. Mike Kent
    Replies:
    0
    Views:
    620
    Mike Kent
    Apr 16, 2009
  3. Roy Smith
    Replies:
    19
    Views:
    573
    Brian
    Feb 12, 2012
  4. Chris
    Replies:
    3
    Views:
    943
    Sisyphus
    Jun 29, 2005
  5. Merrilee Larson

    Do I *have* to use 'OOP' to use modules?

    Merrilee Larson, Nov 17, 2006, in forum: Perl Misc
    Replies:
    41
    Views:
    367
    Arved Sandstrom
    Nov 25, 2006
Loading...

Share This Page