久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <i id='z83DC'><tr id='z83DC'><dt id='z83DC'><q id='z83DC'><span id='z83DC'><b id='z83DC'><form id='z83DC'><ins id='z83DC'></ins><ul id='z83DC'></ul><sub id='z83DC'></sub></form><legend id='z83DC'></legend><bdo id='z83DC'><pre id='z83DC'><center id='z83DC'></center></pre></bdo></b><th id='z83DC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='z83DC'><tfoot id='z83DC'></tfoot><dl id='z83DC'><fieldset id='z83DC'></fieldset></dl></div>
  2. <tfoot id='z83DC'></tfoot>

      <bdo id='z83DC'></bdo><ul id='z83DC'></ul>

    1. <small id='z83DC'></small><noframes id='z83DC'>

      <legend id='z83DC'><style id='z83DC'><dir id='z83DC'><q id='z83DC'></q></dir></style></legend>

      從 python 調試器將變量保存到交互式命名空間

      save variable to interactive namespace from python debugger(從 python 調試器將變量保存到交互式命名空間)
        <bdo id='KeMcN'></bdo><ul id='KeMcN'></ul>
          <i id='KeMcN'><tr id='KeMcN'><dt id='KeMcN'><q id='KeMcN'><span id='KeMcN'><b id='KeMcN'><form id='KeMcN'><ins id='KeMcN'></ins><ul id='KeMcN'></ul><sub id='KeMcN'></sub></form><legend id='KeMcN'></legend><bdo id='KeMcN'><pre id='KeMcN'><center id='KeMcN'></center></pre></bdo></b><th id='KeMcN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='KeMcN'><tfoot id='KeMcN'></tfoot><dl id='KeMcN'><fieldset id='KeMcN'></fieldset></dl></div>
          <legend id='KeMcN'><style id='KeMcN'><dir id='KeMcN'><q id='KeMcN'></q></dir></style></legend>
            <tbody id='KeMcN'></tbody>

            <small id='KeMcN'></small><noframes id='KeMcN'>

                <tfoot id='KeMcN'></tfoot>
              1. 本文介紹了從 python 調試器將變量保存到交互式命名空間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                當我在交互式會話中運行時(在我的例子中是 ipython),并且當前在調試器中(ipdbpdb)我希望能夠從調試命名空間中將變量放入主交互式命名空間.

                When I am running inside an interactive session (in my case ipython), and am currently inside a debugger (ipdb or pdb) I would like to be able to put a variable into the main interactive namespace from within the debugging namespace.

                這在我的代碼崩潰但已經完成大量工作時很有用,其中一些可以挽救以節省時間(例如,從磁盤加載數據).

                This is useful if my code crashes, but has already done significant work, some of which is salvageable to save time (for example, loading data from disk).

                所以我想要的是這樣的,例如:

                so what I'd like is something like this, for example:

                >>> run -m my.module
                loading data from disk...
                done loading data.
                processing data...
                ---------------------------------------------------------------------------
                IndexError                                Traceback (most recent call last)
                ...
                

                -> 這里在處理過程中出了點問題,但是數據的加載工作正常......所以我會進入調試器檢查發生了什么,并查看 loaded_data:

                -> here something goes wrong during processing, but the loading of data worked fine... so I'd go into the debugger to check out what happened, and to see the loaded_data:

                >>> debug
                ipdb> len(loaded_data)
                100000
                

                -> 然后我希望能夠將此變量保存到交互式命名空間中,以便在調試器外部使用,如下所示:

                -> Then I would like to be able to save this variable to the interactive namespace for use outside the debugger, like so:

                ipdb> save_to_interactive('loaded_data')
                ipdb> exit
                >>> len(loaded_data)
                100000
                

                推薦答案

                您可以通過獲取對外部解釋器堆棧的引用來完成此操作框架,并寫入其框架全局變量.

                You can accomplish this by getting a reference to the outer interpreter's stack frame, and writing to its frame globals.

                給定一個帶有斷點的示例模塊,將我們踢到 pdb:

                Given a sample module with a breakpoint that kicks us into pdb:

                my_module.py:

                def fun(arg):
                    import pdb; pdb.set_trace()
                    print arg
                

                演示基本概念的示例:

                    >>> import my_module
                    >>> my_module.fun(1)
                    > /Users/lukasgraf/src/stackoverflow/my_module.py(3)fun()
                    -> print arg
                    (Pdb) import sys
                    (Pdb) sys._getframe(0)
                    <frame object at 0x1032ab290>
                    # this is the current frame
                
                    (Pdb) sys._getframe(0).f_globals['__name__']
                    'my_module'
                
                    # Next outer frame
                    (Pdb) sys._getframe(1).f_globals['__name__']
                    'pdb'
                
                    # etc...
                
                    # In this example, frame 10 happens to be
                    # the one from the outer interpreter
                    (Pdb) sys._getframe(10).f_globals['__name__']
                    '__main__'
                

                所以這里有一個快速而骯臟的函數,它在堆棧中查找 '__name__',在幀全局變量中具有 '__main__' 的值:

                So here's a quick and dirty function that walks up the stack looking for '__name__' with a value of '__main__' in frame globals:

                debughelper.py:

                import sys
                
                # Be safe and define a maximum of frames we're trying to walk up
                MAX_FRAMES = 20
                
                def save_to_interactive(dct):
                    n = 0
                    # Walk up the stack looking for '__name__'
                    # with a value of '__main__' in frame globals
                    for n in range(MAX_FRAMES):
                        cur_frame = sys._getframe(n)
                        name = cur_frame.f_globals.get('__name__')
                        if name == '__main__':
                            # Yay - we're in the stack frame of the interactive interpreter!
                            # So we update its frame globals with the dict containing our data
                            cur_frame.f_globals.update(dct)
                            break
                

                用法:

                >>> import my_module
                >>> my_module.fun('foo')
                > /Users/lukasgraf/src/stackoverflow/my_module.py(3)fun()
                -> print arg
                (Pdb) import debughelper
                (Pdb) debughelper.save_to_interactive({'mykey': 42})
                (Pdb) c
                foo
                # We continued PDB, so we're in the outer interpreter again
                >>> print mykey
                42
                >>>
                

                這篇關于從 python 調試器將變量保存到交互式命名空間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                How to refresh sys.path?(如何刷新 sys.path?)
                Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

                  1. <tfoot id='Mbhte'></tfoot>
                    • <small id='Mbhte'></small><noframes id='Mbhte'>

                      <i id='Mbhte'><tr id='Mbhte'><dt id='Mbhte'><q id='Mbhte'><span id='Mbhte'><b id='Mbhte'><form id='Mbhte'><ins id='Mbhte'></ins><ul id='Mbhte'></ul><sub id='Mbhte'></sub></form><legend id='Mbhte'></legend><bdo id='Mbhte'><pre id='Mbhte'><center id='Mbhte'></center></pre></bdo></b><th id='Mbhte'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Mbhte'><tfoot id='Mbhte'></tfoot><dl id='Mbhte'><fieldset id='Mbhte'></fieldset></dl></div>
                        <tbody id='Mbhte'></tbody>
                        <bdo id='Mbhte'></bdo><ul id='Mbhte'></ul>
                          <legend id='Mbhte'><style id='Mbhte'><dir id='Mbhte'><q id='Mbhte'></q></dir></style></legend>
                        1. 主站蜘蛛池模板: 深夜福利影院 | 97在线观视频免费观看 | 色综合久久久久 | 久久天堂网| 精品久久久999 | 国产一区二区三区色淫影院 | 人人澡视频 | 国产精品91久久久久久 | 日韩一区二区三区av | 亚洲高清视频在线观看 | 九九免费在线视频 | 国产视频精品在线观看 | 国产亚洲一区二区三区 | 久久亚洲国产精品 | www.日韩欧美 | 丁香久久| 天天操夜夜骑 | 在线观看黄免费 | 激情免费视频 | 国产精品成人一区二区三区 | 欧美区日韩区 | 欧美成人免费在线视频 | 亚洲欧美综合 | 日日av| 欧美国产中文字幕 | 亚洲国产欧美日韩 | 欧美国产精品一区二区三区 | 亚洲欧洲精品在线 | www.日本三级| 久久久久久久综合色一本 | www.色综合 | 久久精品欧美一区二区三区麻豆 | 国产精品明星裸体写真集 | 色综合色综合色综合 | 国产乱码一二三区精品 | 国产精品无码专区在线观看 | 精品毛片 | 欧美自拍日韩 | 国产精品亚洲精品日韩已方 | 91久久精| 国产精品久久久久久妇女6080 |