Files
gnucash/bindings/python/example_scripts/simple_book.py
T

25 lines
745 B
Python
Raw Normal View History

#!/usr/bin/env python3
## @file
# @brief Simple example for a book
# @ingroup python_bindings_examples
import sys
2020-06-12 12:24:05 +02:00
from gnucash import Session, SessionOpenMode
2008-07-07 19:18:26 +00:00
# We need to tell GnuCash the data format to create the new file as (xml://)
uri = "xml:///tmp/simple_book.gnucash"
2018-03-22 15:08:22 -07:00
print("uri:", uri)
2020-06-12 12:24:05 +02:00
with Session(uri, SessionOpenMode.SESSION_NEW_STORE) as ses:
2020-02-22 11:28:50 -06:00
book = ses.get_book()
2008-07-07 19:18:26 +00:00
2020-02-22 11:28:50 -06:00
#Call some methods that produce output to show that Book works
book.get_root_account().SetDescription("hello, book")
print("Book is saved:", not book.session_not_saved())
2020-02-22 11:28:50 -06:00
#As long as there's no exceptions, book is automatically saved
#when session ends.
print("saving...")
2008-07-07 19:18:26 +00:00
2018-03-22 15:08:22 -07:00
print("Book is saved:", not book.session_not_saved())