null

What is a 'NoneType' object?

What is a 'NoneType' object? Question: I’m getting this error when I run my python script: TypeError: cannot concatenate ‘str’ and ‘NoneType’ objects I’m pretty sure the ‘str’ means string, but I dont know what a ‘NoneType’ object is. My script craps out on the second line, I know the first one works because the …

Total answers: 13

How to store empty value as an Integerfield

How to store empty value as an Integerfield Question: I’ve seen all the similar threads, read the docs, and tried many combinations to store an empty value as IntegerField in db and failed every single time. I am using MySQL. My models.py defines an age=models.IntegerField() field. I populate db from csv file, and some cells …

Total answers: 3

Peewee syntax for selecting on null field

Peewee syntax for selecting on null field Question: I have researched this everywhere and can’t seem to find an answer. I hope I haven’t duplicated this (as it’s my first question on SO). I am trying to write a select query with Peewee that would normally go … WHERE foo = NULL; in SQL world. …

Total answers: 1

return, return None, and no return at all?

return, return None, and no return at all? Question: Consider these three functions: def my_func1(): print "Hello World" return None def my_func2(): print "Hello World" return def my_func3(): print "Hello World" They all appear to return None. Are there any differences between how the returned value of these functions behave? Are there any reasons to …

Total answers: 5

Pythonic way to determine whether not null list entries are 'continuous'

Pythonic way to determine whether not null list entries are 'continuous' Question: I’m looking for a way to easily determine if all not None items in a list occur in a single continuous slice. I’ll use integers as examples of not None items. For example, the list [None, None, 1, 2, 3, None, None] meets …

Total answers: 11

Django: Want to display an empty field as blank rather displaying None

Django: Want to display an empty field as blank rather displaying None Question: I have a template called client_details.html that displays user, note and datetime. Now sometimes, a client may not have an entry for user, note and datetime. What my program will do instead is display None if these fields are empty. I do …

Total answers: 3

How to insert 'NULL' values into PostgreSQL database using Python?

How to insert 'NULL' values into PostgreSQL database using Python? Question: Is there a good practice for entering NULL key values to a PostgreSQL database when a variable is None in Python? Running this query: mycursor.execute(‘INSERT INTO products (user_id, city_id, product_id, quantity, price) VALUES (%i, %i, %i, %i, %f)’ %(user_id, city_id, product_id, quantity, price)) results …

Total answers: 4

Safe dereferencing in Python

Safe dereferencing in Python Question: Groovy has a nice operator for safe dereferencing, which helps to avoid NullPointerExceptions: variable?.method() The method will only be called, if variable is not null. Is there a way to do the same in Python? Or do I have to write if variable: variable.method()? Asked By: deamon || Source Answers: …

Total answers: 7

Referring to the null object in Python

Referring to the null object in Python Question: How do I refer to the null object in Python? Asked By: Lizard || Source Answers: In Python, the ‘null’ object is the singleton None. To check if something is None, use the is identity operator: if foo is None: … Answered By: Ben James It’s not …

Total answers: 9