金子邦彦研究室インストールWindows の種々のソフトウェア(インストール)ZDOB のインストールと Python プログラム例(Windows 上)

ZDOB のインストールと Python プログラム例(Windows 上)

ZODB はオブジェクトデータベース管理システム

前準備

Python 64 ビット版のインストール,pip と setuptools の更新(Windows 上)

Windows での Python 3.10 のインストール,pip と setuptools の更新: 別ページ »で説明している.

Python の公式ページ: https://www.python.org/

Python 開発環境のインストール

ZODB のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. 次のコマンドを実行してインストール
    python -m pip install zodb
    

[image]

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