Python不会在模块中找到变量 [英] Python won't find variable in module

查看:205
本文介绍了Python不会在模块中找到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始玩Theano,但在Eclipse中有一个奇怪的问题。我正在尝试导入配置模块来运行一些示例代码。新评新新新旗新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗旗新新旗新新旗新旗新旗新旗新旗新旗新旗新旗新旗新旗新旗新新旗新新旗新旗新旗新旗新旗新旗新新旗新旗新旗新旗新旗新旗新旗新新旗新新旗新新旗新旗新旗新旗新旗新新旗新旗新旗新旗新新旗新新旗新新旗旗号旗新新旗新旗新旗新旗新旗新旗新新旗新旗新旗新旗新旗新新旗新旗新旗新旗新旗新旗新旗新新旗新旗新旗新旗新新旗新旗新旗新旗新新旗新旗新旗新旗pre> from theano import config
print config

这样做很好,我得到一个输出:

  floatX(('float64','float32'))
Doc:python转换的默认浮点精度
值:float32
...

还有一些这样的行。不幸的是,如果我使用以下代码,我从theano导入中获取一个import的undefined变量-error:

 新新p新新新旗新新新旗新新旗旗新新旗新新旗新新旗旗新新旗新新旗旗新新旗新新旗新新旗旗新新旗新旗旗新新旗新新旗新旗新旗新新旗新新旗新新旗新新旗旗哨旗新新旗新旗在控制台中我得到float32,这是正确的输出。任何想法为什么会发生这种情况,以及我如何能够给我这个变量背后的价值?谢谢!



系统:OSX 10.9.2 / Python:2.7.6(Macports安装)/ Theano:0.6.0(Macports安装)/ Eclipse:开普勒服务发布2

解决方案

好的,我最后找到了答案。我从来没有错误。 200新新新新旗新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新200新新旗新新旗新新旗200新新新旗新200新新旗新新旗旗哨旗新1992新新旗新1992新新旗新新旗新新款: $ b

如何修复PyDev来自导入的未定义变量 X- 2004545 X- 200 X- 200 X- 200 200 X- 200 200 X- 200 200 X- -40 200 200 -40 200 200 X- 200 200 X- 200 200:新新新新旗新新新旗新新旗新新旗旗新新旗新新旗新新旗新新旗新新旗新新旗200新新新旗新新旗200新新新旗新新旗200新新新旗新新旗200新新新旗新新旗200新新新新旗新新旗新新旗2001-4545 X-对于Mac)在一行错误,pydev将提供一个选项添加注释以忽略该错误。


I just started playing around with Theano but have a strange problem in Eclipse. I am trying to import the config module to run some example code. The import works fine and I can see what's in the module.

Here is the simple code I am trying:

from theano import config
print config

This works fine and I get an output like:

floatX (('float64', 'float32')) 
  Doc:  Default floating-point precision for python casts
  Value:  float32
...

and some more lines like that. Unfortunately if I use the following code, I get an "undefined variable from import"-error for the floatX:

from theano import config
print config.floatX

This is only happening in Eclipse. In the console I get "float32", which is the correct output. Any idea why this is happening and how I can get to give me the value behind that variable? Thank you!

System: OSX 10.9.2 / Python: 2.7.6 (Macports installation) / Theano: 0.6.0 (Macports installation) / Eclipse: Kepler Service Release 2

解决方案

ok, I found the answer finally. I never really had an error. I did not find that out because I never tried to actually run the script because the editor indicated there was an error... The maker of PyDev answered the following question himself and provides a workaround:

How do I fix PyDev "Undefined variable from import" errors?

For code in your project, the only way is adding a comment saying that you expected that (the static code-analysis only sees what you see, not runtime info -- if you opened that module yourself, you'd have no indication that main was expected).

You can use ctrl+1 (Cmd+1 for Mac) in a line with an error and pydev will present you an option to add a comment to ignore that error.

这篇关于Python不会在模块中找到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆