Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rajashree-k
Copy link

No description provided.

# 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:
Copy link

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?

Copy link
Author

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.

Copy link

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).

Copy link
Author

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:
Copy link

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?

Copy link
Author

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..

Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants