Skip to content

Instantly share code, notes, and snippets.

@drheinheimer
Last active October 4, 2018 18:14
Show Gist options
  • Save drheinheimer/334bf958ca2064642cd81d1e0cb4b9b2 to your computer and use it in GitHub Desktop.
Save drheinheimer/334bf958ca2064642cd81d1e0cb4b9b2 to your computer and use it in GitHub Desktop.
Read a Paradox database table (for example from WEAP)
import os
from pypxlib import Table
def db(dir, name):
filelist = os.listdir(dir)
dbname = '{}.db'.format(name)
dbname = dbname if dbname in filelist else dbname.replace('.db', '.DB')
if dbname not in filelist:
return
mbname = dbname.replace('.db', '.MB').replace('.DB', '.MB')
if mbname not in filelist:
mbname = None
file_path = os.path.join(dir, dbname)
blob_file_path = os.path.join(dir, mbname) if mbname else None
return Table(file_path=file_path, blob_file_path=blob_file_path)
data = db('./SJN_R3', 'Data')
with data as table:
for row in table:
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment