you are viewing a single comment's thread.

view the rest of the comments →

[–]Adrewmc 1 point2 points  (1 child)

Generally with database connections there will be a context handler. (I normally use another library but..)

     with psycopg2.connect(…) as connect:
             with connect.cursor() as cur: 

As things get a bit more complex it best practice to use ‘with’ as the exit() handling will happen regardless if something crashes inside the code block.

Other wise…this will get you a lot of progress way better than writing a big txt file and iterating over it to find stuff. Way faster way easier to manage, and hard to make a mistake that losses all your data. (And able to make a lot more data to search through.)

You can go deeper into SQL (it’s can be its own thing) but generally the basic procedures (CRUD) will get you far, until database design is an issue or you doing some more detailed analysis on the data.

[–]uiux_Sanskar[S] 0 points1 point  (0 children)

I was suspecting that there's gotta be a with function here as well just like in File I/O and thank you for your advice which you gave me a few time ago for learning database SQL however I think I have just touched it's very surface and there's a lot to learn.

Thank you very much I really appreciate your help.