Skip to content
Browse files
Monkey patch __nonzero__ onto QPyNullVariant for easier null check.
Who doesn't love monkeys :)
  • Loading branch information
NathanW2 committed Jun 11, 2013
1 parent 3115c30 commit 8392c93d8e6de82ff12330af1b79b8437e76ec0f
Showing with 12 additions and 0 deletions.
  1. +12 −0 python/
@@ -22,3 +22,15 @@
__copyright__ = '(C) 2007, Martin Dobias'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtCore import QPyNullVariant
from types import MethodType

# Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier.
# >>> value = QPyNullVariant("int")
# >>> if value:
# >>> print "Not a null value"
def __nonzero__(self):
return False

QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)

1 comment on commit 8392c93


This comment has been minimized.

Copy link

@slarosa slarosa commented on 8392c93 Jun 11, 2013

Hi Nathan,
after this commit I am unable to start up my standalone application or python script neither from IDE application nor from Python Console. Therefore even the 'Run Script' command in Python Console does not work. I always get:

Traceback (most recent call last):
  File "/home/sam/", line 2, in 
    from qgis.core import *
  File "/usr/local/share/qgis/python/qgis/", line 26, in 
    from PyQt4.QtCore import QPyNullVariant
ImportError: cannot import name QPyNullVariant

Do you have any hint ?

Please sign in to comment.