获取ipdb的IPython选项卡完成

时间:2013-02-27 21:04:01

标签: python debugging ipython pdb

我安装了IPython(0.13.1)ipdb(0.7),我在我的脚本中插入了行import ipdb;ipdb.set_trace()并运行了python my_script.py。现在我在ipdb提示符下并且有一些自动完成(例如一个裸标签),但它与我进入IPython时获得的自动完成功能不同。在ipdb提示符requests.中,<tab>(导入后)没有像IPython那样提供属性列表。如何使用ipdb获得与IPython相同的选项卡完成?

顺便说一句,当我运行python -m ipdb my_script.py时,标签完成的工作方式与IPython一样,但其缺点是它从第一行启动调试器而不是我放置import ipdb;ipdb.set_trace()的行。

5 个答案:

答案 0 :(得分:6)

我在Mac上使用ipython==0.13.2ipdb==0.7 Python 2.7.5 virtualenv中出现了同样的现象。当我尝试调试时,我有内置函数的选项卡完成,但不适用于当前范围中的变量。我发现,我的主文件夹(http://docs.python.org/2/library/pdb.html#id2)中有一个自定义.pdbrc。在我评论完所有内容之后,标签完成再次起作用。

我不知道何时以及为何添加此文件,但这就是其中的内容:

# See http://docs.python.org/2/library/pdb.html#id2 for the structure of this file.
import pdb

# 'inspect x' will print the source code for a method, class or function.
alias inspect import inspect;print inspect.getsource(%1)
alias i import inspect;print inspect.getsource(%1)
# 'help x' opens the man-style help viewer from the interpretter on an object
alias help !print help(%1)
alias h !print help(%1)
# For ordinary Python objects, ppo will pretty-print members and their values.
alias ppo pp %1.__dict__
# ppio runs ppo over a sequence of objects
alias ppio pp [a.__dict__ for a in %1]

# This tries to enable tab-completion of some identifiers.
!import rlcompleter
!pdb.Pdb.complete = rlcompleter.Completer(locals()).complete

# Taken from https://gist.github.com/1125049
# There are a couple of edge cases where you can lose terminal
# echo. This should restore it next time you open a pdb.
!import termios, sys
!termios_fd = sys.stdin.fileno()
!termios_echo = termios.tcgetattr(termios_fd)
!termios_echo[3] = termios_echo[3] | termios.ECHO
!termios_result = termios.tcsetattr(termios_fd, termios.TCSADRAIN, termios_echo)

需要进一步的研究来检查那里的标签完成是什么......

答案 1 :(得分:3)

easy_install readline有帮助吗?

答案 2 :(得分:2)

我遇到了同样的问题,我用以下方法解决了这个问题:

sudo pip install --upgrade ipdb ipython readline

如果您没有安装readline,请务必安装libncurses5-dev @ musashi14建议。

答案 3 :(得分:1)

我在ubuntu 14.04上遇到了同样的问题,并修复了:

{{not checked}}

apt-get install libncurses5-dev

答案 4 :(得分:0)

截至 2019-11 ,有几处更改,因此以下是应解决的问题:

var sem = new SemaphoreSlim(25);

            var chunksTasks = appIds.Select(async (a, i) =>
            {
                //  is it possible to change ip proxy here ?  

                await sem.WaitAsync(300);

                var response = new CheckPackageResponse
                {
                    AppId = a,
                };

                string url;

                if (a.All(Char.IsDigit))
                {
                    url = $"https://apps.apple.com/ru/app/id{a}?dataOnly=true&isWebExpV2=true";
                }
                else
                {
                    url = $"https://play.google.com/store/apps/details?id={a}";
                }

                try
                {
                    using (var resp = await _client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
                    {
                        response.HttpStatus = (int) resp.StatusCode;

                        return response;
                    }
                }
                catch (Exception e)
                {
                    _log.LogError(e.Message);
                    _log.LogError("Inner: " + e.InnerException?.Message);
                    return response;
                }
                finally
                {
                    sem.Release();
                }
            }).ToList();