Skip to main content

Changing values

To change the value of a Node, you must use the set method from the parent Node.

set will create new values if they don't exist, but this can be changed by setting the create_if_not_exist flag to False. This way it will just raise a NameError.

Command usage:

PYNdatabase.set(name, val, create_if_not_exist=True)
PYNdatabase.Node.set(name, val, create_if_not_exist=True)

Examples:

Basic usage:

from pyndb import PYNDatabase
db = PYNDatabse('filename.pyndb')
db.set('hello', 'world')  # <-- (creating value since none exists)
db.save()  # Remember to save if needed!

Don't create new values:

from pyndb import PYNDatabase
db = PYNDatabse('filename.pyndb')

# This will work...
db.create('hello')
db.set('hello', 'world', create_if_not_exist=False)

# But this will not.
db.set('hello', 'world', create_if_not_exist=False)