Skip to content

Commit a647cd3

Browse files
authored
Merge branch 'master' into skip-ahead-with-continue
2 parents 2020fc7 + 1666e7b commit a647cd3

File tree

250 files changed

+7602
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+7602
-58
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "wordcount",
3+
"image": "mcr.microsoft.com/devcontainers/python:3.13-bookworm",
4+
"workspaceFolder": "/workspaces/materials/wordcount",
5+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/materials,type=bind",
6+
"postCreateCommand": {
7+
"project": "python -m pip install -r requirements.txt -e . && rm -rf src/*.egg-info/",
8+
"help": "echo 'echo -e \"💡 Run \\e[1mpytest --task\\e[0m to display instructions for the current task.\n💡 Run \\e[1mpytest\\e[0m to evaluate your solution and track your progress.\"' >> ~/.bashrc"
9+
},
10+
"customizations": {
11+
"codespaces": {
12+
"openFiles": [
13+
"src/wordcount.py"
14+
]
15+
},
16+
"vscode": {
17+
"extensions": [
18+
"ms-python.python"
19+
]
20+
}
21+
}
22+
}

debug-python-errors/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# How to Debug Common Python Errors
2+
3+
This folder provides the code examples for the Real Python tutorial [How to Debug Common Python Errors](https://realpython.com/debug-python-errors/).

debug-python-errors/cat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cat = "Siamese"
2+
3+
print(cat)

debug-python-errors/fruit.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def capitalize_fruit_names(fruits):
2+
capitalized_fruit_names = []
3+
cleaned = [fruit if isinstance(fruit, str) else "" for fruit in fruits]
4+
5+
for fruit in cleaned:
6+
capitalized_fruit_names.append(fruit.capitalize())
7+
8+
return capitalized_fruit_names
9+
10+
11+
if __name__ == "__main__":
12+
print(capitalize_fruit_names(["apple", "BANANA", "cherry", "maNgo"]))

debug-python-errors/palindromes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def find_palindromes(text):
2+
# Split sentence into words
3+
words = text.split()
4+
5+
# Remove punctuation and convert to lowercase
6+
normalized_words = [
7+
"".join(filter(str.isalnum, word)).lower() for word in words
8+
]
9+
10+
# Check for palindromes
11+
return [word for word in normalized_words if word == word[::-1]]
12+
13+
14+
if __name__ == "__main__":
15+
print(
16+
find_palindromes("Dad plays many solos at noon, and sees a racecar.")
17+
)

debug-python-errors/test_fruit.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import unittest
2+
3+
from fruit import capitalize_fruit_names
4+
5+
6+
class TestFruit(unittest.TestCase):
7+
def test_empty_list(self):
8+
"""with empty list"""
9+
self.assertEqual(capitalize_fruit_names([]), [])
10+
11+
def test_lowercase(self):
12+
"""with lowercase strings"""
13+
self.assertEqual(
14+
capitalize_fruit_names(["apple", "banana", "cherry"]),
15+
["Apple", "Banana", "Cherry"],
16+
)
17+
18+
def test_uppercase(self):
19+
"""with uppercase strings"""
20+
self.assertEqual(
21+
capitalize_fruit_names(["APPLE", "BANANA", "CHERRY"]),
22+
["Apple", "Banana", "Cherry"],
23+
)
24+
25+
def test_mixed_case(self):
26+
"""with mixed case strings"""
27+
self.assertEqual(
28+
capitalize_fruit_names(["mAnGo", "grApE"]),
29+
["Mango", "Grape"],
30+
)
31+
32+
def test_non_string_element(self):
33+
"""with a mix of integer and string elements"""
34+
self.assertEqual(
35+
capitalize_fruit_names([123, "banana"]),
36+
["", "Banana"],
37+
)
38+
39+
40+
if __name__ == "__main__":
41+
unittest.main()

loguru/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# How to Use Loguru for Simpler Python Logging
2+
3+
This repository contains code related to the Real Python tutorial [How to Use Loguru for Simpler Python Logging](https://realpython.com/python-loguru/).
4+
5+
## Setup
6+
7+
You should first create and activate a virtual environment:
8+
9+
```sh
10+
$ python -m venv venv/
11+
$ source venv/bin/activate
12+
```
13+
14+
Install the pinned dependencies from `requirements.txt`:
15+
16+
```sh
17+
(venv) $ python -m pip install -r requirements.txt
18+
```
19+
20+
Then you can execute the provided Python scripts, for example:
21+
22+
```sh
23+
(venv) $ python basic_logging.py
24+
```

loguru/basic_logging.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from loguru import logger
2+
3+
logger.debug("Debug message")
4+
logger.info("Info message")
5+
logger.error("Error message")

loguru/catch_and_log_errors.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from loguru import logger
2+
3+
4+
@logger.catch
5+
def divide(a, b):
6+
return a / b
7+
8+
9+
divide(10, 0)

loguru/context_logging.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
3+
from loguru import logger
4+
5+
logger.remove()
6+
logger.add(sys.stderr, format="{time} | {level} | {message} | {extra}")
7+
8+
user_logger = logger.bind(user_id=123)
9+
user_logger.info("User logged in")
10+
user_logger.info("User started a session")
11+
12+
with logger.contextualize(request_id="abc789"):
13+
logger.info("Processing request")
14+
logger.info("Request completed")
15+
16+
logger.info("Request is processed, this will not show extra context")

0 commit comments

Comments
 (0)