By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,996 Members | 1,498 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,996 IT Pros & Developers. It's quick & easy.

Code execution in imported modules

P: n/a
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!
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Eric Wertman wrote:
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.
It is compiled when you import the module.

--
Hans Nowak (zephyrfalcon at gmail dot com)
http://4.flowsnake.org/
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.