检查对象是否为 None 的最佳方法?

Best way to check if an object is None?

我该如何解决这个错误?似乎是此存储库中未解决的问题: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:

if idxiter is None:
    ...

它更安全,尤其是因为并非所有对象都支持与 None 的相等比较。