开发者

ipython showing gibberish when debugging Django with Netbeans

I'm using Netbeans for coding Django. When I insert:

import ipdb; ipdb.set_trace()

Flow execution gets stopped but it shows gibberish, such as:

[1;32m/path/to/file/models.py[0m(344)[0;36macceptBid[1;34m()[0m
[1;32m    343 [1;33m        [1;32mimport[0m [1;37mipdb[0m[1;33m;[0m [1;37mipdb[0m[1;33m.[0m[1;37mset_trace[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[0m[1;32m--> 344 [1;33m   开发者_开发百科     [1;32mreturn[0m [1;37mself[0m[1;33m.[0m[1;37msenderId[0m[1;33m([0m[1;33m)[0m [1;33m==[0m [1;37muser_obj[0m[1;33m.[0m[1;37mid[0m[1;33m[0m[0m
[0m[1;32m    345 [1;33m[1;33m[0m[0m
[0m

I can use next, skip and everything from pdb. But I can not see where I'm in the code, which forces me to use pdb instead of ipdb.


for me worked fine with just commenting the line and add a pass sentence in ipdb/__main__.py

    from IPython.utils import io

    def update_stdout():
        # setup stdout to ensure output is available with nose

        #THIS IS THE LINE TO COMMENT #########################
        #io.stdout = sys.stdout = sys.__stdout__ 

        #REMEMBER TO ADD pass
        pass                                     
else:
    from IPython.Debugger import Pdb, BdbQuit_excepthook
    from IPython.Shell import IPShell
    from IPython import ipapi


These are ANSI escape codes, which are used for the text colours in ipdb's output. For some reason, the terminal you're debugging in is not accepting the codes and is printing them as text. You may be able to find a setting in NetBeans to either change what the terminal is reporting itself as, or what it actually accepts.


This is the problem: https://github.com/gotcha/ipdb/issues/31

and you can solve it by commenting out a line in ipdb/_ _ main _ _.py


What I have done to be able to use ipdb with Django Netbeans, is disable coloring output in ipdb. There are several ways to do this. If you have installed ipdb through easy_install you can edit the code in __init__.py leaving it like:

import sys
from IPython.Debugger import Pdb
from IPython.Shell import IPShell
from IPython import ipapi

shell = IPShell(argv=[''])

def set_trace():
    Pdb("NoColor").set_trace(sys._getframe().f_back)

Also you can create yourself a hook to import ipdb without colors. I hope this helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜