-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[build-system] | ||
requires = ["setuptools >= 61.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
|
||
name = "itemattribute" | ||
version = "0.0.1" | ||
dependencies = [] | ||
requires-python = ">= 3.7" | ||
authors = [{name = "Andy Mounce", email = "[email protected]"}] | ||
description = "Python class that allows dict item syntax for attribute access" | ||
readme = {file = "README.txt", content-type = "text/markdown"} | ||
license = {file = "LICENSE"} | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/ammounce/itemattribute" | ||
Issues = "https://github.com/ammounce/itemattribute/issues" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .item_attribute import ItemAttribute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
|
||
class ItemAttribute(object): | ||
''' | ||
Class that has properties which can be called like dictionary | ||
items | ||
Parameters | ||
---------- | ||
dictionary : dict | ||
Dictionary object, defaults to None, contains initial | ||
attributes for ItemAttribute instance. | ||
''' | ||
|
||
def __init__(self, dictionary=None): | ||
if dictionary is not None: | ||
for k in dictionary.keys(): | ||
self[k] = dictionary[k] | ||
|
||
__getitem__ = object.__getattribute__ | ||
__setitem__ = object.__setattr__ | ||
__delitem__ = object.__delattr__ | ||
|
||
def keys(self): | ||
''' | ||
Returns a list of keys. | ||
''' | ||
return self.__dict__.keys() | ||
|
||
def values(self): | ||
''' | ||
Returns a list of values. | ||
''' | ||
return self.__dict__.values() | ||
|
||
def items(self): | ||
''' | ||
Returns a list of key:value pairs. | ||
''' | ||
return self.__dict__.items() | ||
|
||
def __contains__(self, item): | ||
''' | ||
Overloads the `key in object` syntax to check if | ||
`key in obj.__dict__` | ||
''' | ||
|
||
return item in self.__dict__ |