difference between set default and set null
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
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.
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden