Keen Learner and Exp... • 1d
Day 25 of learning python as a beginner. Topic: database handling. I used to write simple programs which just showed some text in the console when I started learning python. I didn't used to store that data somewhere because I didn't know how to. Then I got introduced to File I/O in python and I aggressively started using .txt files to store data however it was very time consuming and code extensive to perform operations on that data. Then someone told me to check out JSON files and this reduced a lot of code from my program as I am now able to perform CURD operation more easily. However I still can't use it as a database that's when someone guided me to learn about Database handling in python by using SQL at that time I decided to focus on the basics however I have decided to learn them in future and today's that day. I decide to learn PostgreSQL with SQLAlchemy (I haven't even seen a drop of it just learned to install and connect it to python and use it as a simple database). There's a lot more things learn in this. As we all know database is an organised set of information stored efficiently and for effective future use. first I have downloaded and imported psycopg2 which is a popular library to help python programs to connect and interact with PostgreSQL. Then I connected psycopg2 with my data base by giving all the necessary details (hid the password of course). The I wrote my first SQL query and according to my experience unlike python SQL is not case sensitive i.e. it can also be written in small case letters. Also the queries of SQL to me seemed to me more like just writing English sentences with a few technical jargons. .cursor is used to execute the command in the actual database and .commit saves all the changes in the database. It is a good practice to close both so that they can get a signal that we are done for now and I also created a small database of people using python. And here's my code and its database.
Hey I am on Medial • 28d
🚀 Level Up Your Skills for FREE! Whether you're a student, professional, or lifelong learner—these curated courses are your gateway to growth in tech, data, and business. 🎓 Explore top-tier content in: 1. Artificial Intelligence + Data Analyst
See MoreDownload the medial app to read full posts, comements and news.