简体   繁体   English

Eclipse - python 的交互式 shell 不工作

[英]Eclipse - interactive shell for python not working

I've installed and configured Pydev with Eclipse but when I try to use interactive shell I get errors.我已经使用 Eclipse 安装并配置了 Pydev,但是当我尝试使用交互式 shell 时出现错误。 Can someone have a look and advise?有人可以看看和建议吗?

Code for two functions:两个函数的代码:

def convert_milage(t):  # t - number of miles per 1 gallon
    litersPer100Kilometers = 100/ ((t * 1.609) / 3.785) 
    return litersPer100Kilometers

def liters_needed(t, v): # t: distance in kms, v: fuel consumption
    fuelConsumption = convert_milage(v)
    litersNeeded = (t * fuelConsumption) / 100
    return litersNeeded

Error: http://i54.tinypic.com/2afmu7p.png错误: http://i54.tinypic.com/2afmu7p.png

Error message:错误信息:

>>> convert_milage(100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'convert_milage' is not defined
>>> 

You need to open the console for the file you're in, not just use the general python console, as that knows nothing about the functions in your source file.您需要为您所在的文件打开控制台,而不仅仅是使用一般的 python 控制台,因为它对源文件中的功能一无所知。

Press Ctrl-Alt-Enter and select Current active editor .Ctrl-Alt-Enter和 select Current active editor

That should import the current module into your shell and make things work better.这应该将当前模块导入您的 shell 并使事情更好地工作。

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

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