简体   繁体   English

在ipython中选中完整的字典键

[英]tab complete dictionary keys in ipython

I was wondering if anybody knows how to enable or implement tab completion for dictionary keys in IPython? 我想知道是否有人知道如何在IPython中启用或实现字典键的Tab键完成? It seems like it wouldn't be very different from functionality that already exists, like tab completion of object attributes. 它似乎与已存在的功能(例如对象属性的选项卡完成)没有太大差别。 If I'm wrong, then I'd like to understand why 如果我错了,那么我想了解原因

IPython supports dict key completion for string keys since version 3.0.0 (despite not appearing in release notes), thanks to this patch . 由于这个补丁 ,IPython支持从3.0.0版开始的字符串密钥的dict密钥完成(尽管没有出现在发行说明中)。 It also supports column name completion for numpy struct arrays and pandas DataFrame columns, and for other types that redefine __getitem__ through defining _ipython_key_completions_ . 它还支持numpy struct数组和pandas DataFrame列的列名完成,以及通过定义_ipython_key_completions_重新定义__getitem__其他类型。

It's not built into IPython 2.x. 它没有内置到IPython 2.x中。 If you want to add it, have a look at this, where someone hacked a solution: 如果你想添加它,看看这个,有人攻击了解决方案:

https://github.com/ipython/ipython/issues/1533 https://github.com/ipython/ipython/issues/1533

Also, there are many short and easy ways to create objects from dictionaries, to gain the usual tab completion. 此外,还有许多简单易用的方法可以从字典中创建对象,以获得通常的制表符。 If that would help you, use one of the ways described in this question: 如果这对您有帮助,请使用此问题中描述的方法之一:

Convert Python dict to object? 将Python dict转换为对象?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM