Reputation: 9773
If I have a python module that at the start of the time (not in a function or class) reads a value from a file, does that get executed every time? or does the pyc file read the value in a stores the value in the compiled file?
Upvotes: 0
Views: 89
Reputation: 90027
Short of using reload
, a module will only be imported and executed once, the first time your program imports it. Further imports of the same module just bind the existing name in the scope where the import happens, so the read will only be done once.
If you're asking whether the compilation step reads the file and embeds it in the .pyc
, then no. The code isn't run at all at compilation time.
Upvotes: 2