如何读取Python内存中的代码文件?

2024-09-23 08:23:12 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我实际得到的错误/回溯:

Traceback (most recent call last):
  File "/home/apache/tactic/src/tactic/ui/panel/custom_layout_wdg.py", line 619, in process_mako
    html = template.render(server=my.server, search=Search, sobject=sobject, sobjects=my.sobject_dicts, data=my.data, plugin=plugin, kwargs=my.kwargs)
  File "/home/apache/tactic/src/mako/template.py", line 189, in render
    return runtime._render(self, self.callable_, args, data)
  File "/home/apache/tactic/src/mako/runtime.py", line 403, in _render
    _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data))
  File "/home/apache/tactic/src/mako/runtime.py", line 434, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/home/apache/tactic/src/mako/runtime.py", line 457, in _exec_template
    callable_(context, *args, **kwargs)
  File "memory:0x7f2ea8589810", line 19, in render_body
    ${gl.get_gantt('vfx')}
  File "/home/apache/gantt_logic.py", line 34, in get_gantt
    prepend.add_style("width: %spx" %(total_width/days * (start_date - process[1]["start"]).days))
ZeroDivisionError: integer division or modulo by zero

我不是在问如何修复ZeroDivisionError错误。那是微不足道的。你知道吗

我想知道的是,如何读取Python内存中的文件?在这种情况下memory:0x7f2ea8589810。你知道吗


Tags: inpysrchomemyapachemakoline
1条回答
网友
1楼 · 发布于 2024-09-23 08:23:12

我现在不知道你的情况,但import linecache是一个模块,你会问如果你需要一个文件行。你知道吗

我还认为traceback对这行使用linecache:

${gl.get_gantt('vfx')}

因此,我认为希望读取生成的代码的开发人员应该创建linecache支持。你知道吗

尝试:

import linecache
print(linecache.getlines("memory:0x7f2ea8589810"))

或者类似的。你知道吗

相关问题 更多 >