简体   繁体   English

什么是“文件”<string> &quot;&#39; 代表 python 调试器和回溯?

[英]What does 'File "<string>"' stands for on python debugger and traceback?

Eventually, when I am in a debug session, the current file is named "<string>".最终,当我在调试会话中时,当前文件被命名为“<string>”。 What I would expect to see is the name of the module where the debugger is currently on.我希望看到的是调试器当前所在模块的名称。

The same happens on the traceback:回溯上也会发生同样的情况:

Traceback (most recent call last):
  ...
  File "~/project_x/app/services/contacts.py", line 23, in find_account
  account = self._account_repo.get_by_id(id)
  File "<string>", line 2, in get_by_id
  File "~/project_x/lib/python3.7/site-packages/pony/orm/core.py", li
ne 528, in new_func
    result = func(*args, **kwargs)

It means that the code came from something that was not a file, but a string.这意味着代码来自不是文件而是字符串的东西。 My guess would be an exec() call, but maybe there are other ways of getting the same effect.我的猜测是exec()调用,但也许还有其他方法可以获得相同的效果。 The previous stack frame might give some clues.之前的堆栈帧可能会提供一些线索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM