Advanced Search
Search Results
51 total results found
Reloading/retrieving the data from the file
To reload the data from the file, use the following method: File.reload() This method is only 1 line of code: self.data = self.read_data() The read_data method returns the data stored in the file, after being parsed into a python dictionary.
Moving beyond a single flat file
For more complex projects, a flat-file database may not be the way to go. Here is one example of how you could store data in a more distributed way: db folder users user1.pyn user2.pyn etc transactions 001.pyn 002.pyn etc config.json ...
How to fix pyntree installing as UNKNOWN-0.0.0
pip install --upgrade pip wheel setuptools
Installing
pyntree is available via pip: pip install pyntree That's it!
Encrypting a file
Encryption is a new feature as of 1.0.0! To use encryption, first type pip install pyntree[encryption] to install the necessary dependencies. To encrypt your data, simply specify a password parameter for the Node when saving or loading. db = Node('encrypted...
Getting the name of a Node
Syntax: Node._name Let's say you have a miscellaneous Node that got passed to a function somehow. What is its purpose? The name of the Node may shed some light on this: from pyntree import Node x = Node('test.pyn') x._name # 'test.pyn' x.a = 1 x.a._n...
The where() method
Syntax: Node.where(**kwargs) Let's say you have a lot of users, sorted by IDs. Now, you want to find a user with a specific, unique email. Sounds like a pain, right? Nope. Here's how to do it with pyntree: db = Node("users.pyn") my_user = db.where(email=...
Converting back to a dictionary
Syntax: dict(Node) This is pretty straightforward, as shown above. The command will make a new dictionary. If you want to directly manipulate a Node's data instead, you can simply perform methods on the called function, as shown in the section Math and obj...
Node representation
Syntax: str(Node) # or repr(Node) str(Node) will return a string representation of the data stored within the Node repr(Node) will return the same as str(Node), but wrapped within the text "Node()"
Math and object manipulation
Syntax: Node += val Math operations If you used pyndb, you probably had to do something like this: x = PYNDatabase({}) x.set("a", 1) x.set("a", x.a.val + 1) Let's be real here, this SUCKS. pyntree does it better: x = Node() x.a = 1 x.a += 1 Wow, t...
Getting the children
Syntax: Node._children The ._children property returns a list of Node objects (the children of the parent Node)