Execution of import statements

28 views
Skip to first unread message

Mark Billion

unread,
Apr 28, 2016, 7:20:59 PM4/28/16
to web2py-users
I understand that the whole default.py file is executed on each request to a function internal to it. But does it import if the statement evaluates to false?

For example if default.py has:

Function x():
If 1==2:
Import a

Does a get imported every time function x is called?

Niphlod

unread,
Apr 29, 2016, 3:23:40 AM4/29/16
to web2py-users
in python if you have 


import a
blablabla
import b
blablabla
import a

the second "import a" statement is executed, but is a no-op.

Mark Billion

unread,
Apr 29, 2016, 9:32:05 AM4/29/16
to web2py-users
Right, but if the import is a conditional one -- ie, only import a if a condition evals to true -- does it no op the import if the condition goes to false or does it import all and then execute?

Niphlod

unread,
Apr 29, 2016, 9:34:39 AM4/29/16
to web2py-users
it's like math with parenthesis...

if b == 1:
     import a

will trigger "import a" when b == 1 . the first time b==1 it'd be a real import, the second time it'd be a no-op

if b is never going to be == 1, import will be never triggered.
Reply all
Reply to author
Forward
0 new messages