ZDOB のインストールと Python プログラム例(Windows 上)
ZODB はオブジェクトデータベース管理システム
前準備
Python 64 ビット版のインストール,pip と setuptools の更新(Windows 上)
Windows での Python 3.10 のインストール,pip と setuptools の更新: 別ページ »で説明
Python の公式ページ: https://www.python.org/
Python 開発環境のインストール
- Windows での Python 開発環境として,Jupyter Qt Console, Jupyter ノートブック (Jupyter Notebook), Jupyter Lab, Nteract, spyder のインストール: 別ページ »で説明
- Windows での PyCharm のインストール: 別ページ »で説明
- Windows での PyScripter のインストール: 別ページ »で説明
ZODB のインストール(Windows 上)
-
Windows で,コマンドプロンプトを管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
次のコマンドを実行してインストール
python -m pip install zodb

ZODB のプログラムを動かしてみる
http://www.zodb.org/en/latest/documentation/tutorial.html (現存しない) に記載されていた account.py を使っている.
Python プログラムを実行する
import persistent
import ZODB, ZODB.FileStorage, ZODB.DB
import BTrees.OOBTree
class Account(persistent.Persistent):
def __init__(self):
self.balance = 0.0
def deposit(self, amount):
self.balance += amount
def cash(self, amount):
assert amount < self.balance
self.balance -= amount
storage = ZODB.FileStorage.FileStorage('mydata.fs')
db = ZODB.DB(storage)
connection = db.open()
root = connection.root
# create one object
root.accounts = BTrees.OOBTree.BTree()
root.accounts['account-1'] = Account()
root.accounts['account-1'].balance