Best way to check if an object is None?

吃可爱长大的小学妹 提交于 2019-12-04 06:25:49

问题


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()

回答1:


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

if idxiter is None:
    ...

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



来源:https://stackoverflow.com/questions/49186324/best-way-to-check-if-an-object-is-none

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!