Skip to content

Add example using 'with' statement and urlopen#672

Open
njneered wants to merge 1 commit intorealpython:masterfrom
njneered:add-urlopen-with-example
Open

Add example using 'with' statement and urlopen#672
njneered wants to merge 1 commit intorealpython:masterfrom
njneered:add-urlopen-with-example

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