通过在命令行中将对象暴露给 python 程序,我得到了大量的实用程序。例如:
myprog.py obj1.obj2.method
让我执行 obj1.obj2.method(),然后
myprog.py obj1.<TAB>
myprog.py obj1.obj2<TAB>
让我看看有什么可用的。惊人的!但是,我无法说服 jedi 返回自动完成结果列表(或字典)。我希望这可能适用于短名单:
class X:
pass
x = X()
x2 = X()
x2.y = 456
x.z = [x2]
# Want to get x.z[0].y in the results
prefix = "x.z[0]."
import jedi
# Tell jedi about list elements?
script = jedi.Interpreter(prefix, [{"x.z[0].z": x.z[0].z}])
for c in script.completions():
print c
sys.exit()