Skip to content

Add example using 'with' statement and urlopen #672

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

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

Conversation

njneered
Copy link

@njneered njneered commented Jun 3, 2025

This pull request adds a beginner-friendly Python example to demonstrate the use of the with statement with urllib.request.urlopen() for safely opening and reading a URL. This addresses Issue #423.

The example is located in:
context-managers/urlopen-example/with_urlopen_example.py

It includes a simple script that fetches content from https://www.python.org and prints the first 200 bytes. The code also contains helpful comments for learners.

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.

1 participant