0

Okay, so this is the strangest thing I've seen happen in a pretty long time. So, I fire up vs2012 like I normally do, and start some imports. I have a module I'm working with, and I import it via static import from the root of my module.

import os
from foo.bar import bang

I execute these in the interpreter... and all of a sudden, my exceptions don't work.

I type in, assert 1 == 2, and nothing happens. I type in x[1], and nothing happens. No x is undefined, no assertionerror, nothing.

Okay, so I restart my interpreter, and just do the assertion statement. It works fine.

Has anyone ever seen anything like this? What could possibly be causing it? (Yes, I know it's the imported module, but seeing as it's quite a bit of code, perhaps a place to start looking before I go diving into the depths?)

[edit]

Running commands in the interactive seem to take a long time, too-- dir() took like 3 seconds to come up with a list 8 or so items long.

4

1 回答 1

3

这是一种可能性:

import sys

def hook(type, value, traceback):
    pass

sys.excepthook = hook
assert 1 == 2

在这种情况下,断言不会打印任何内容。您可以通过查看 if 来验证这一点sys.excepthook != sys.__excepthook__

注意:以 ipython 为例,这个值是傻瓜。因此,如果您正在对此进行测试,请确保您只使用python而不是ipython.

于 2013-03-05T21:36:24.533 回答