Skip to content

Commit

Permalink
Writing to Binary File functionality added | Updated to v0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhashish-Chakraborty committed Nov 23, 2024
1 parent aec587b commit 872b4ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pyfilemaster/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import pickle
import csv

def writeBinFile(path, data):
"""
Writes data to a binary `.dat` file.
Parameters:
path (str): Path to the `.dat` file (with or without extension(.dat)).
data (list): List of dictionaries to be stored in the file.
"""

if (path.lower()[-1:-5:-1][::-1] == ".dat"):
path = path.lower().rstrip(".dat")
else:
pass

try:
with open(path + ".dat", "ab") as f:
for record in data:
pickle.dump(record, f)
print(f"Data successfully written to {path}.dat")
except Exception as e:
print(f"An error occurred: {e}")

def readBinFile(path):
"""
Reads and prints the contents of a binary `.dat` file.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='pyfilemaster', # Package name
version='0.1.3', # Initial release version
version='0.1.4', # Initial release version
author='beingshubh (Shubhashish Chakraborty)', # Author name
author_email='[email protected]', # Author email
description='A Python package for file handling utilities', # Short description
Expand Down

0 comments on commit 872b4ad

Please sign in to comment.