检查对象是否为无的最佳方法? [英] Best way to check if an object is None?

查看:59
本文介绍了检查对象是否为无的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决此错误?似乎是该存储库中未解决的问题: https://github.com/shayanzare007/EntitySentiment/issues /7

How should I fix this error? Seems like an unresolved issue in this repository: https://github.com/shayanzare007/EntitySentiment/issues/7

$ python RunRNN.py 
Number of unique words: 9869
Opening the file...
File successfully read
Opening the file...
File successfully read
Opening the file...
File successfully read
Number of training samples 5003
Traceback (most recent call last):
  File "RunRNN.py", line 84, in <module>
    curve = model.train_sgd(X,Y,idxiter_random,None,400,400) 
  File "/scratch2/debate_tweets/sentiment/EntitySentiment/nn/base.py", line 386, in train_sgd
    if idxiter == None: # default training schedule
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

推荐答案

在测试对象是否为空时,建议的做法是始终使用is:

When testing an object for nullity, the recommended practice is to always use is:

if idxiter is None:
    ...

这更安全,尤其是因为并非所有对象都支持与None进行相等比较.

It's safer, especially because not all objects support equality comparisons with None.

这篇关于检查对象是否为无的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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