NOTICE: All information contained herein is, and remains
the property of TechnoCore Automate.
The ObjImportApi class in ObjDataImportFwf.py imports data from
Fixed-Width Format (FWF) files, also known as flat files or positional files.
Each column occupies a fixed character range on every line.
This format is common in mainframe exports, banking bureau files (e.g. Experian
flat-file feeds), and legacy government data sets.
Uses only stdlib — no third-party dependency. Files are streamed line by line.
prep_file(filename) -> strNo-op — returns the filename unchanged.
open_file(filename)Opens the file for streaming. If field_specs is set, column names are derived
from it; otherwise a single "line" column is used and each row is returned
as-is.
close_file()Closes the file handle.
column_list() -> listReturns column names derived from field_specs, or ["line"] if not set.
next_row() -> list | strReads the next non-empty line and slices it per field_specs. Values are
stripped of leading/trailing whitespace. Returns "EOF" when exhausted.
Set field_specs before calling open_file:
importer = ObjImportApi()
importer.field_specs = [
("id", 0, 5), # chars 0-4
("name", 5, 25), # chars 5-24
("score", 25, 30), # chars 25-29
]
importer.open_file("bureau_export.txt")
Each tuple is (column_name, start, end) using 0-based Python slice semantics
(start inclusive, end exclusive).
importer = ObjImportApi()
importer.field_specs = [
("AccountNo", 0, 12),
("Balance", 12, 22),
("Status", 22, 30),
]
importer.open_file("collections_extract.txt")
columns = importer.column_list()
while True:
row = importer.next_row()
if row == "EOF":
break
print(dict(zip(columns, row)))
importer.close_file()
Updated : 2026-03-13