Skip to content

Commit

Permalink
README tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Fison committed Nov 1, 2020
1 parent 5cc5b2d commit 25d67f2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ Or using the ```.fromlist()``` method like this:
>>> x._3
'three'

The ```.fromlist()``` method was added specifically to help with serialisation issues like json.dumps() converting numeric dictionary keys to strings, and for use with Client/Server apps such as the excellent Anvil.works which allows you to pass custom objects of a 'portable' Class between Client and Server.
The ```.fromlist()``` method was added specifically to help with serialisation issues like ```json.dumps()``` converting numeric dictionary keys to strings, and for use with Client/Server apps such as the excellent Anvil.works which allows you to pass custom objects of a 'portable' Class between Client and Server.

To generate the corresponding list of key/value pairs from a CleverDict object, just use the ```.tolist()``` method like this:
To generate the corresponding list of key/value pairs from a ```CleverDict``` object, just use the ```.tolist()``` method like this:

>>> x = CleverDict({1: "one", 2: "two"})

Expand Down Expand Up @@ -160,7 +160,7 @@ Did you also know that since [PEP3131](https://www.python.org/dev/peps/pep-3131/
We've included the ```.setattr_direct()``` method in case you want to set an object attribute *without* creating the corresponding dictionary key/value. This could be useful for storing save data for example, and is used internally to store aliases in ```._aliases```. Variables which have been set directly in this way are stored in ```_vars```.

>>> x = CleverDict()
>>> x.setattr_direct("direct",False)
>>> x.setattr_direct("direct", False)

>>> x
CleverDict({}, _aliases={}, _vars={'direct': False})
Expand Down Expand Up @@ -228,7 +228,7 @@ If you want to specify different ```.save``` behaviours for different objects, c

We'd love to see Pull Requests (and relevant tests) from other contributors, particularly if you can help evolve ```CleverDict``` to make it play nicely with other classes simply using inheritance, without causing recursion or requiring a rewrite/overwrite of the original class.

For example it would be amazing if we could do something as simple as this:
For example it would be great if we could graft on the CleverDict methods to other Classes, something like this:

>>> class MyDatetime(datetime.datetime, CleverDict):
... pass
Expand All @@ -239,6 +239,11 @@ For example it would be amazing if we could do something as simple as this:
>>> mdt['hour']
4

Unfortunately at the moment this raises an error:
```TypeError: multiple bases have instance lay-out conflict```

... which is beyond the author's current Python level!


## 12. CREDITS
```CleverDict``` was developed jointly by Ruud van der Ham, Peter Fison, Loic Domaigne, and Rik Huygen who met on the friendly and excellent Pythonista Cafe forum (www.pythonistacafe.com). Peter got the ball rolling after noticing a super-convenient, but not fully-fledged feature in Pandas that allows you to (mostly) use ```object.attribute``` syntax or ```dictionary['key']``` syntax interchangeably. Ruud, Loic and Rik then started swapping ideas for a hybrid dictionary/data class, originally based on ```UserDict``` and the magic of ```__getattr__``` and ```__setattr__```.
Expand Down

0 comments on commit 25d67f2

Please sign in to comment.