【问题标题】:How to read code file that are in the Python memory?如何读取 Python 内存中的代码文件?
【发布时间】:2014-01-30 09:01:25
【问题描述】:

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

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

【问题讨论】:

  • 用例是什么?我的意思是你想在这里实现什么?
  • 好奇心。此外,它可能对社区有益。
  • 它不是内存中的文件,它是内存地址(无论有什么)。见stackoverflow.com/questions/8250625/…

标签: python


【解决方案1】:

我现在不了解您的情况,但 import linecache 是您会询问是否需要文件行的模块。

我也认为 traceback 对这一行使用了 linecache:

${gl.get_gantt('vfx')}

所以我认为希望生成的代码被读取的开发人员应该创建 linecache 支持。

尝试:

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

或类似的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多