Skip to content

Latest commit

 

History

History
172 lines (101 loc) · 5.38 KB

toolshed_types_nakedobject.rst

File metadata and controls

172 lines (101 loc) · 5.38 KB

Toolshed: types : NakedObject

Import NakedObject

from Naked.toolshed.types import NakedObject

Import NakedObject from C Module

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.

Description

A NakedObject is a generic object that supports equality testing based upon the contents of its attributes.

Examples

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