Skip to content

Commit f74d551

Browse files
authoredAug 5, 2024
Ensure JsonDB uses script directory for default data.json path
1 parent 257c8a9 commit f74d551

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed
 

‎jsonDB.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import json
3+
import os
34
from collections.abc import MutableMapping
45

56

@@ -12,6 +13,10 @@ def __init__(self, filename='data.json'):
1213
1314
:param filename: The path to the JSON file used for data storage. Defaults to 'data.json'.
1415
"""
16+
if not os.path.isabs(filename):
17+
# If the filename is not an absolute path, set it to the directory of the script file
18+
script_dir = os.path.dirname(os.path.realpath(__file__))
19+
filename = os.path.join(script_dir, filename)
1520
self.filename = filename
1621
self._data = self.load_data()
1722

0 commit comments

Comments
 (0)
Please sign in to comment.