The current code in Accessing and Managing Financial Data assumes in the section "Setting up a Database" that the data directory already exists.
When running the command tidy_finance = sqlite3.connect(database="data/tidy_finance_python.sqlite") without previously creating the data directory, SQLite will throw an OperationalError: unable to open database file.
This can be avoided by explicitly checking whether the directory exists and creating it if it doesn't:
# Define the path to the database
database_path = "data/tidy_finance_python.sqlite"
directory = os.path.dirname(database_path)
# Create the directory if it doesn't exist
if not os.path.exists(directory):
os.makedirs(directory)
Alternatively of course, you could just mention in the text that the data-directory has to be created beforehands.
If I missed that part - sorry and please disregard this issue! :)
The current code in Accessing and Managing Financial Data assumes in the section "Setting up a Database" that the
data
directory already exists. When running the commandtidy_finance = sqlite3.connect(database="data/tidy_finance_python.sqlite")
without previously creating thedata
directory, SQLite will throw anOperationalError: unable to open database file
.This can be avoided by explicitly checking whether the directory exists and creating it if it doesn't:
Alternatively of course, you could just mention in the text that the
data
-directory has to be created beforehands.If I missed that part - sorry and please disregard this issue! :)