如何忽略Pydev Eclipse中的特定未定义变量 [英] Howto ignore specific undefined variables in Pydev Eclipse

查看:128
本文介绍了如何忽略Pydev Eclipse中的特定未定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse与Pydev插件在Windows上编写一个跨平台的python脚本。该脚本使用 os.symlink() os.readlink()方法,如果当前平台isn' t NT。



由于 os.symlink() os.readlink()方法在Windows平台上不可用Pydev将它们标记为未定义的变量,如下所示:





问题:



有没有办法忽略特定的未定义的变量名错误而不修改源文件?



编辑:我发现了一种忽略来自这个答案在stackoverflow。

我会把问题放在万一有解决这个使用的项目文件或Pydev的设置方式。


解决方案

我怀疑的PyDev可能有更好,具体的解决方案,但是如果只是把一些代码放在你的程序的开始,如下所示:

  if not hasattr(os,'symlink' ):os.symlink =无

是的,这是一个黑客,但除非pydev 有专门的解决方案(不幸的是我不知道有什么,但是我没有pydev专家;-),可能比没有更好...


I'm writing a crossplatform python script on windows using Eclipse with the Pydev plugin. The script makes use of the os.symlink() and os.readlink() methods if the current platform isn't NT.

Since the os.symlink() and os.readlink() methods aren't available on the Windows platform Pydev flags them as undefined variables--like so:

Question:

Is there a way to ignore specific undefined variable name errors without modifying my source file?

edit: I found a way to ignore undefined variable errors from this answer on stackoverflow.
I'll leave the question open in case there is a way to solve this using project file or Pydev setting.

解决方案

I suspect pydev may have better, specific solutions, but what about just putting some code at the start of your program, such as:

if not hasattr(os, 'symlink'): os.symlink = None

Yeah, it's a hack, but, unless pydev does have specialized solutions (unfortunately I don't know of any, but then I'm no pydev expert;-), may be better than nothing...

这篇关于如何忽略Pydev Eclipse中的特定未定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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