from Naked.toolshed.types import NakedObject
from Naked.toolshed.c.types import NakedObject
The C module must be compiled before you import it. See the naked build documentation for more information.
A NakedObject
is a generic object that supports equality testing based upon the contents of its attributes.
Create a New Instance of an Empty NakedObject
from Naked.toolshed.types import NakedObject
obj = NakedObject()
Create a New Instance of a NakedObject with Attributes
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
Determine Type of NakedObject
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
print(type(obj)) # prints <class 'Naked.toolshed.types.NakedObject'>
Set New Attribute on NakedObject
from Naked.toolshed.types import NakedObject
obj = NakedObject()
obj.example = 'an example string'
Get Attribute Value from NakedObject
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
the_value = obj.example
Delete Attribute from NakedObject
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
del obj.example
Test for Existence of an Attribute
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
if hasattr(obj, 'example'):
# do something with the attribute
Equality Testing of NakedObjects
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
obj2 = NakedObject({'example': 'an example string'})
print(obj.equals(obj2)) # prints True
print(obj == obj2) #prints True
Equality Testing of NakedObjects, Failure on Different Attributes
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
obj2 = NakedObject({'different': 'an example string'})
print(obj.equals(obj2)) # prints False
print(obj == obj2) # prints False
Equality Testing of NakedObjects, Failure on Different Attribute Values
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
obj2 = NakedObject({'example': 'different'})
print(obj.equals(obj2)) # prints False
print(obj == obj2) # prints False
Equality Testing of NakedObjects, Failure on Different Attribute Number
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
obj2 = NakedObject({'example': 'an example string', 'example2': 'another string'})
print(obj.equals(obj2)) # prints False
print(obj == obj2) # prints False
Equality Testing of NakedObject, Failure on Different Type
from Naked.toolshed.types import NakedObject
obj = NakedObject({'example': 'an example string'})
obj2 = "an example string"
print(obj.equals(obj2)) # prints False
print(obj == obj2) # prints False