-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session3_Homework_Vcet_puttur_4VP20CS070_RAJASHREE #7
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajashree-k Why with
is used? what is with
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with statement is used for exception handling. So it make the code cleaner and much more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajashree-k If any exception occurs in this loop, what happens to the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.