function is called with the name "productid"the stockitem class gains the attribute __productid which holds the product id' valueand the descriptor productid attribute which is used to access the value for exampleif we create an item using item stockitem("tv""tva ""electrical" )we can get the product id using item productid and set it usingfor exampleitem productid "tvb the getter function created by the decorator simply uses the global getattr(function to return the value of the private data attribute the setter function incorporates the validationand at the enduses setattr(to set the private data attribute to the new (and validvalue in factthe private data attribute is only created the first time it is set once the getter and setter functions have been created we use setattr(once againthis time to create new class attribute with the given name ( productid)and with its value set to be descriptor of type genericdescriptor at the endthe decorator function returns the modified classand the valid_string(function returns the decorator function the valid_number(function is structurally identical to the valid_string(functiononly differing in the arguments it accepts and in the validation code in the setterso we won' show it here (the complete source code is in the valid py module the last thing we need to cover is the genericdescriptorand that turns out to be the easiest partclass genericdescriptordef __init__(selfgettersetter)self getter getter self setter setter def __get__(selfinstanceowner=none)if instance is nonereturn self return self getter(instancedef __set__(selfinstancevalue)return self setter(instancevaluethe descriptor is used to hold the getter and setter functions for each attribute and simply passes on the work of getting and setting to those functions