I'm confused about why, when an error is raised in a function within a module I've written, IPython doesn't show me a full traceback with the line in the function that caused the error.
Note: I'm not confused about the cause of this particular error, but about why IPython isn't showing me the cause.
My module is called module.py
and it contains the function function
, underneath which is written an if __name__ == '__main__'
block. (Module and function names have been changed to protect the identities of the innocent -- or maybe not so innocent.)
Here's the traceback I get when an error is raised. (Note the lack of information about which line in function
caused the error.)
In [1]: import module as m
In [2]: call = m.function('hello')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-ec0c1e40ec8c> in <module>()
----> 1 call = m.function('hello')
/home/module.py in function(greeting)
TypeError: join() takes exactly one argument (2 given)
if __name__ == "__main__"
bit? Is the function defined in that block? If so, I'm not sure how your function call even worked at all. Can you give a SSCCE of the module? – Ariumjoin()
calls infunction
. The traceback does not tell me which one raised the error. This is unusual; the traceback would normally point me to the line in the source code that raised the error. Something is different about this situation, and I'm not sure what it is. – Ivattsmodule.py
with a function that simply raises aTypeError
, and aif __name__ == "__main__":
block that just has a print statement. Does this produce the error for you? If not, can you come up with a minimal example to reproduce the error? If so, can you provide some details of your setup (Python version, Ipython version, etc.)? – Nucleiif __name__ == '__main__'
block. That would be outrageous. Furthermore, in my question I state that this block is "underneath" the function. To clarify, theif __name__ == '__main__'
block is below the completed function definition, below thereturn
statement. – Ivattsfunction
in theif __name__ == '__main__'
block. I'll report back as soon as I'm able to come up with a helpful example. – Ivatts__builtin__
when you run the modulle / import it. – Southerland