Skip to content

Commit 8392c93

Browse files
committedJun 11, 2013
Monkey patch __nonzero__ onto QPyNullVariant for easier null check.
Who doesn't love monkeys :)
1 parent 3115c30 commit 8392c93

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎python/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@
2222
__copyright__ = '(C) 2007, Martin Dobias'
2323
# This will get replaced with a git SHA1 when you do a git archive
2424
__revision__ = '$Format:%H$'
25+
26+
from PyQt4.QtCore import QPyNullVariant
27+
from types import MethodType
28+
29+
# Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier.
30+
# >>> value = QPyNullVariant("int")
31+
# >>> if value:
32+
# >>> print "Not a null value"
33+
def __nonzero__(self):
34+
return False
35+
36+
QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)

1 commit comments

Comments
 (1)

slarosa commented on Jun 11, 2013

@slarosa
Member

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/clipper.py", line 2, in 
    from qgis.core import *
  File "/usr/local/share/qgis/python/qgis/__init__.py", line 26, in 
    from PyQt4.QtCore import QPyNullVariant
ImportError: cannot import name QPyNullVariant

Do you have any hint ?

Please sign in to comment.