python - Jython does not catch Exceptions -


jython doesn't have -m option, , raises error from .utils import *.

the solution not use relative path

sys.path.insert(0, os.path.dirname(__file__)) utils import * 

as need use code both jython , cpython, came command:

try:     .utils import * except exception: # jython or python python context/context.py invocation     sys.path.insert(0, os.path.dirname(__file__))     utils import * 

however, jython doesn't seem catch exception, , still generates exception.

  file "context/context.py", line 9 syntaxerror: 'import *' not allowed 'from .' 

based on how know interpreter jython or cpython in code?, tried

binary = sys.executable if binary none:     sys.path.insert(0, os.path.dirname(__file__))     utils import * else:     .utils import * 

i still syntaxerror, why jython interpreter keeps parsing from .utils import * when supposed so; mean, code works.

binary = sys.executable if binary none:     sys.path.insert(0, os.path.dirname(__file__))     utils import * else:     pass 

this jython information:

jython 2.7b1 (default:ac42d59644e9, feb 9 2013, 15:24:52)  [java hotspot(tm) 64-bit server vm (oracle corporation)] on java1.7.0_51 type "help", "copyright", "credits" or "license" more information. 

somehow doesn't relative import, thinking 2 possibles solutions:

  • try import utils package root of project.
  • add path utils package pythonpath.

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -