Session3_Homework_Vcet_puttur_4VP20CS070_RAJASHREE#7
Session3_Homework_Vcet_puttur_4VP20CS070_RAJASHREE#7rajashree-k wants to merge 1 commit intoUniCourt:mainfrom
Conversation
| # This function will add the entry to database | ||
| sql = """INSERT INTO members_blog (title, release_date, blog_time, author, created_date, content, recommended, path) VALUES (%s, %s::DATE, %s::TIME, %s, NOW(),%s,%s,%s)""" | ||
|
|
||
| with conn: |
There was a problem hiding this comment.
@rajashree-k Why with is used? what is with?
There was a problem hiding this comment.
with statement is used for exception handling. So it make the code cleaner and much more readable.
There was a problem hiding this comment.
@rajashree-k could you please explain in detail, what exception handling you're referring to?
( I don't mind even if you write 100 lines of explanation but if you're not sure so as to why with is used, please look up on the internet).
There was a problem hiding this comment.
with statement is closes the connection and cursor automatically.
| fp=open("scrap_data.html","w") | ||
| path=os.path.abspath("scrap_data.html") | ||
|
|
||
| for blog in blogs: |
There was a problem hiding this comment.
@rajashree-k If any exception occurs in this loop, what happens to the file?
There was a problem hiding this comment.
I think file will create, but if any exception occurs in the loop that time it might stops execution of the next line. Because here not used any exception handling like with, try & catch..
There was a problem hiding this comment.
@rajashree-k it's obvious that the moment your code encounters a exception it would break and stop the execution of code. But the question still stands, what happens to the opened file?
No description provided.