No line number shown for run-time error from Python module -


most python errors produce traceback showing line number of offending statement. reason run-time errors not.

for instance, running "python -m mymodule.py" on module containing 2 lines:

args = {} if len(args > 2): print("this run-time error. should be: len(args) > 2") 

fails with:

c:\python34\python.exe: error while finding spec 'mymodule.py' (<class 'typeerror'>: unorderable types: dict() > int()) 

this sample of code larger module failed and, having no line number made hard find coding error.

when use -m, python searches sys.path module, , it's not finding file specified. because path doesn't (and reasons of stability , security shouldn't) include current working directory.

since error produced @ command line rather inside file, there no line number error.

finally, fix problem, type

python -m ./mymodule 

this fixes 2 problems command line:

  1. the .py extension omitted when doing module import.

  2. you need explicitly add path in order import module (or move directory in sys.path).


Comments

Popular posts from this blog

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

node.js - Using Node without global install -

java - JavaScript + Thymeleaf - select onchange -