Code execution in imported modules

Discussion in 'Python' started by Eric Wertman, May 30, 2008.

  1. Eric Wertman

    Eric Wertman Guest

    So I'm working on some file parsing and building up a stack of regular
    expressions that I need to use. I was thinking of dropping them in an
    external module. I was wondering.. if I put them in a file called
    regex.py like so :

    import re

    re1 = "..
    re2 = "..

    and then do:

    rgx1 = re.compile(re1)
    rgx2 = re.compile(re2)


    and, in my script, parse.py py I do:

    from regex import *

    text = "bunch of stuff......."

    m = rgx1.search(text)


    Does the re get compiled when I import it, or every time I call it?
    Since I'm calling it often, I'd like to compile it once.

    Thanks!
     
    Eric Wertman, May 30, 2008
    #1
    1. Advertisements

  2. Eric Wertman

    Hans Nowak Guest

    It is compiled when you import the module.
     
    Hans Nowak, May 30, 2008
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.