简体   繁体   English

Sublime Text 2.自动完成python`from`

[英]Sublime Text 2. Autocomplete python `from`

I am using SublimeRope plugin. 我正在使用SublimeRope插件。 When I am typing from foo.b it displays the autocomplete dialog with random crap but what I am really looking for is to recognize bar module inside the foo package. 当我from foo.b输入时from foo.b它会显示带有随机垃圾的自动完成对话框,但我真正想要的是识别foo包中的bar模块。 However if I type from foo import b it immediately suggest me to import bar as a module. 但是,如果我from foo import b键入from foo import b它会立即建议我导入bar作为模块。 Which means Rope "knows" about that module. 这意味着Rope“知道”该模块。 How can I configure my Sublime to help me suggest the imports when from foo.b ? 如何配置我的Sublime以帮助我from foo.b建议导入?

I am doing projects with django so the real example it wont me to autocomplete from django.contrib. 我正在用django做项目,所以我不会from django.contrib.自动完成这个真实的例子from django.contrib. but if I type from django.contrib.auth.models import U it suggest me to import user. 但如果我from django.contrib.auth.models import U键入它,它建议我导入用户。

You should definitely be using SublimeJEDI for Python autocompletion! 你绝对应该使用SublimeJEDI进行Python自动完成! There's no way around Jedi awesomeness. 杰迪绝对没有办法。

This is just a Sublime Plugin for the Jedi library (which is definitely better than Rope, but I'm biased because I'm the author). 这只是Jedi库的Sublime插件(肯定比Rope好,但我有偏见,因为我是作者)。

Just adding to what other have said sublimecodeintel can help you with this. 只是添加其他人说sublimecodeintel可以帮助你。 However to get it working with Django as you would like you have to add a configuration file pointing to django to your project. 但是要让它与Django一起工作,你需要添加一个指向django的配置文件到你的项目中。 The instructions for how to do this are on the github page linked above. 有关如何执行此操作的说明,请参见上面链接的github页面。 You'll add something similar to this: 你会添加类似的东西:

    {
"Django":{
    "django":'/Users/bin/python2.7/site-packages/django'
    },
}

Have you checked out SublimeCodeIntel ? 你检查过SublimeCodeIntel吗? It's available through Package Control , and has this functionality. 它可通过Package Control获得 ,并具有此功能。 The initial indexing of your packages may take some time, but once it's all set (you may need to restart Sublime once or twice to get everything loaded) it works like a charm. 你的软件包的初始索引可能需要一些时间,但是一旦完成设置(你可能需要重新启动Sublime一次或两次以使所有内容都加载)它就像一个魅力。

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

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