Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

difference between set default and set null

By
elakkiya
on 6/3/13, 2:59 AM 1,300 views

difference between set default and set null

0

patrick

--patrick--
1958
| 5 4 7
Baarn, Netherlands
--patrick--
patrick
On 6/3/13, 5:44 AM

Set default means that the variable gets the default value (which can be Null). Default values are defined in the module.

Set null sets the variable to null, even though the default value is set to be different.

At the following site, they give an example:

#!/usr/bin/python
dict = {'Name': 'Zara', 'Age': 7}

print "Value : %s" %  dict.setdefault('Age', None)
print "Value : %s" %  dict.setdefault('Sex', None)

When running the program, you get:

Value : 7
Value : None

So dict.setdefault tries to get the key from the dictionary. If not found, it uses the default, which is specified as second value in the parameter.

As you can see, the sex is None, even though people usually have one sex (male/female). The usage of setdeault is to prevent the program to throw an error, or even causing the program to halt due to an uncaught error.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 6/3/13, 2:59 AM
Seen: 1300 times
Last updated: 3/16/15, 8:10 AM