Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Huston Petty2,833 Points
Python Databases VS CSV/Excel Files
I'm not sure if this kind of question is allowed or not. I am currently going through the Python Databases course and I just need to be sold a little more on using Databases in Python.
I am already quite comfortable in Python. I create tools at work with it all the time. Recently I have started building in a logging/database system into all of my tools to have a record of when my tools are used, who used it, time taken to run, files processed, etc. I do this by just creating a "data.csv" file and having the tool add a new row everytime the tool is ran with all of the desired info.
So my question is...what is the benefit of using a Database over a CSV file (specifically through a Python script)? It seems a little more out of the way and complicated than just using a CSV file. Especially since I can easily open a CSV in Excel and get sums and averages of different columns of data.
Make no mistake I am not questioning that Databases are not useful in general, I am just wondering if it is useful to use it for Python scripts. Thanks in advance.
Jennifer NordellTreehouse Teacher
Hi there! Of course, this question is allowed! But I think there might be some misconception here about a database vs your CSV/Excel file. To be clear, those are also databases but are what we refer to as "flat-file" databases. They are not what we call "relational" databases. And the reason to use a relational database over a "flat-file" database would be the same regardless of which language you are using.
Here's a fairly concrete example. You said that right now, you are collecting the names of everyone using your tools and each time you make a new row with the name and other information. My last name is Nordell. But what if I get married this weekend and my last name changes? All of your previous entries would point to my former name, but maybe you have 10,000 users. Maybe you don't want to keep up with name changes. The benefit here is that you can make that change in one place instead of replicating and replacing the data everywhere. My name would be linked to a unique ID that then holds my name (first and last). Because everything is related to that unique ID, when you then update my last name in the database, it changes everywhere.
There is nothing specific about the Python language that makes a database more or less efficient than a CSV. It depends largely on your data and what you're using it for.
Hope this helps!
Huston Petty2,833 Points
Ok gotcha. Great advice. Thank you both so much. I really appreciate it. :D