【问题标题】:Working in PyDev console , But not when running in eclipse在 PyDev 控制台中工作,但不是在 eclipse 中运行时
【发布时间】:2014-07-03 22:11:22
【问题描述】:

我正在用 PythonCook Book 学习 python。我遇到了一个场景,我不知道为什么会这样。当我在 PyDev 控制台中运行以下代码时,它运行良好。

>>> user_record =('Dave', 'dave@example.com', '773-555-1212', '847-555-1212')
>>> name, email, *phone_numbers = user_record
>>> name
'Dave'
>>> email
'dave@example.com'
>>> phone_numbers
['773-555-1212', '847-555-1212']

但是当我在 Eclipse 中运行代码时,我收到以下错误,例如“未定义的变量名”

这里的概念是什么?我对python真的很陌生

【问题讨论】:

  • 你在每个版本上运行什么 python 版本?
  • @InbarRose python 3.4
  • 对于像这样的小东西,只需将其放入脚本文件并运行该文件就很容易了。这样你就可以跟踪你所做的一切。此外,一个非常流行的控制台环境是 Ipython。
  • @JustinEngel 我在文件中运行时收到此错误。它在 pyDevConsole 中工作正常

标签: python eclipse


【解决方案1】:

这是我运行的文件。有用。我不知道为什么它会给你一个错误,除非你把“>>>”放在文件中。

def main():
    user_record = ('Dave', 'dave@example.com', '773-555-1212', '847-555-1212')
    name, email, *phone_numbers = user_record
    print(name)
    print(email)
    print(phone_numbers)
# end main

if __name__ == "__main__":
    main()

输出:

Dave
dave@example.com
['773-555-1212', '847-555-1212']

【讨论】:

  • 我在问题中使用 ">>>" 让其他人知道我在 python 开发控制台中成功运行了代码。我在文件中成功运行了您的代码。但是日食仍然在第三行显示红色标记。这就是我要问的。
  • 我认为唯一会成为问题的另一件事是,如果您没有正确配置解释器或将 () 放在姓名、电子邮件、*电话号码周围。 “(姓名,电子邮件,*电话号码)=用户记录”
猜你喜欢
  • 1970-01-01
  • 2014-04-24
  • 2013-07-24
  • 1970-01-01
  • 1970-01-01
  • 2015-05-31
  • 2014-09-29
  • 1970-01-01
  • 2016-08-20
相关资源
最近更新 更多