python - 我如何在 IronPython 中打印脚本行号?

标签 python ironpython

我在 C# 应用程序中运行 IronPython 脚本,我在脚本中捕获异常,我希望找出引发异常的脚本行。这必须在脚本运行时完成,即。我不希望脚本为了打印异常而终止。

这可能吗?

最佳答案

如果 inspect 在 IronPython 下按预期工作(不太确定),这可以解决问题:

import inspect

filename, linenum, funcname = inspect.getframeinfo(inspect.currentframe())[:3]
print linenum

编辑:备用解决方案:

import sys

frame = sys._getframe()
print frame.f_lineno

关于python - 我如何在 IronPython 中打印脚本行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3161177/

相关文章:

c# - 停止 IronPython 中运行的所有线程

python - 为什么 id( )'s result on IronPython equal to id()' s 在 Python 上没有结果?

c++ - C/C++ 中的 Cython

python - 错误 : unpack_from requires a buffer

Python def 标记为无效语法

ironpython - Spotfire IronPython 脚本滚动过滤器并每一步更新可视化(通过日期范围播放按钮)

python - 是否可以将 bbox_to_anchor 放入 matplotlibrc 文件中?

python - 为什么在sklearn线性回归中intercept_是一个数组?

c# - 在 Unity 5.3.1f 中使用 C# 动态类型

python - 带 WPF 的 IronPython 中的消息框