Skip to content

Commit 8190985

Browse files
Merge branch 'polars-missing-data' of https://github.com/realpython/materials into polars-missing-data
2 parents 20a0dda + 8b61efc commit 8190985

Some content is hidden

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

78 files changed

+1270
-247
lines changed

basic-input-output-in-python/adventure_game.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
enemy_health = 3
55

66
while health > 0 and enemy_health > 0:
7-
if input("Attack or Run? ").lower() == "attack":
7+
# Normalize input to handle extra spaces and case variations.
8+
action = input("Attack or Run? ").strip().lower()
9+
if action not in {"attack", "run"}:
10+
print("Invalid choice. Please type 'Attack' or 'Run'.")
11+
continue
12+
13+
if action == "attack":
814
enemy_health -= 1
915
print("You hit the enemy!")
1016
# Implement a 50% chance that the enemy strikes back.

basic-input-output-in-python/guess_the_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
if guess == number:
77
print("You got it!")
88
else:
9-
print(f"Sorry, the number was {number}.")
9+
print("Sorry, the number was", number)
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
amqp==5.1.1
2-
asgiref==3.5.2
3-
async-timeout==4.0.2
4-
billiard==3.6.4.0
5-
celery==5.2.7
6-
click==8.1.3
7-
click-didyoumean==0.3.0
1+
amqp==5.3.1
2+
asgiref==3.8.1
3+
billiard==4.2.1
4+
celery==5.4.0
5+
click==8.1.7
6+
click-didyoumean==0.3.1
87
click-plugins==1.1.1
9-
click-repl==0.2.0
10-
Deprecated==1.2.13
11-
Django==4.0.6
12-
kombu==5.2.4
13-
packaging==21.3
14-
prompt-toolkit==3.0.30
15-
pyparsing==3.0.9
16-
pytz==2022.1
17-
redis==4.3.4
8+
click-repl==0.3.0
9+
Django==5.1.3
10+
kombu==5.4.2
11+
prompt_toolkit==3.0.48
12+
python-dateutil==2.9.0.post0
13+
redis==5.2.0
1814
six==1.16.0
19-
sqlparse==0.4.2
20-
vine==5.0.0
21-
wcwidth==0.2.5
22-
wrapt==1.14.1
15+
sqlparse==0.5.2
16+
tzdata==2024.2
17+
vine==5.1.0
18+
wcwidth==0.2.13
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
amqp==5.1.1
2-
asgiref==3.5.2
3-
async-timeout==4.0.2
4-
billiard==3.6.4.0
5-
celery==5.2.7
6-
click==8.1.3
7-
click-didyoumean==0.3.0
1+
amqp==5.3.1
2+
asgiref==3.8.1
3+
billiard==4.2.1
4+
celery==5.4.0
5+
click==8.1.7
6+
click-didyoumean==0.3.1
87
click-plugins==1.1.1
9-
click-repl==0.2.0
10-
Deprecated==1.2.13
11-
Django==4.0.6
12-
kombu==5.2.4
13-
packaging==21.3
14-
prompt-toolkit==3.0.30
15-
pyparsing==3.0.9
16-
pytz==2022.1
17-
redis==4.3.4
8+
click-repl==0.3.0
9+
Django==5.1.3
10+
kombu==5.4.2
11+
prompt_toolkit==3.0.48
12+
python-dateutil==2.9.0.post0
13+
redis==5.2.0
1814
six==1.16.0
19-
sqlparse==0.4.2
20-
vine==5.0.0
21-
wcwidth==0.2.5
22-
wrapt==1.14.1
15+
sqlparse==0.5.2
16+
tzdata==2024.2
17+
vine==5.1.0
18+
wcwidth==0.2.13

django-user-management/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Get Started With Django User Management
2+
3+
Follow the [step-by-step instructions](https://realpython.com/django-user-management/) on Real Python.
4+
5+
## Setup
6+
7+
You can run the provided example project on your local machine by following the steps outlined below.
8+
9+
Create a new virtual environment:
10+
11+
```bash
12+
$ python3 -m venv venv/
13+
```
14+
15+
Activate the virtual environment:
16+
17+
```bash
18+
$ source venv/bin/activate
19+
```
20+
21+
Install the dependencies for this project if you haven't installed them yet:
22+
23+
```bash
24+
(venv) $ python -m pip install -r requirements.txt
25+
```
26+
27+
Navigate into the project's directory:
28+
29+
```bash
30+
(venv) $ cd user_auth_intro/
31+
```
32+
33+
Make and apply the migrations for the project to build your local database:
34+
35+
```bash
36+
(venv) $ python manage.py makemigrations
37+
(venv) $ python manage.py migrate
38+
```
39+
40+
Run the Django development server:
41+
42+
```bash
43+
(venv) $ python manage.py runserver
44+
```
45+
46+
Navigate to `http://localhost:8000/dashboard` to see the project in action.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
asgiref==3.8.1
2+
Django==5.1.3
3+
sqlparse==0.5.2
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "user_auth_intro.settings")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()

django-user-management/user_auth_intro/user_auth_intro/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for user_auth_intro project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "user_auth_intro.settings")
15+
16+
application = get_asgi_application()
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Django settings for user_auth_intro project.
3+
4+
Generated by 'django-admin startproject' using Django 5.1.3.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = (
24+
"django-insecure-%&$tji0geb7vpx8@9-&qbf3_%3$s=5*5amo4tr)yg!6&6@bbhl"
25+
)
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
32+
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
33+
34+
35+
# Application definition
36+
37+
INSTALLED_APPS = [
38+
"users.apps.UsersConfig",
39+
"django.contrib.admin",
40+
"django.contrib.auth",
41+
"django.contrib.contenttypes",
42+
"django.contrib.sessions",
43+
"django.contrib.messages",
44+
"django.contrib.staticfiles",
45+
]
46+
47+
MIDDLEWARE = [
48+
"django.middleware.security.SecurityMiddleware",
49+
"django.contrib.sessions.middleware.SessionMiddleware",
50+
"django.middleware.common.CommonMiddleware",
51+
"django.middleware.csrf.CsrfViewMiddleware",
52+
"django.contrib.auth.middleware.AuthenticationMiddleware",
53+
"django.contrib.messages.middleware.MessageMiddleware",
54+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
55+
]
56+
57+
ROOT_URLCONF = "user_auth_intro.urls"
58+
59+
TEMPLATES = [
60+
{
61+
"BACKEND": "django.template.backends.django.DjangoTemplates",
62+
"DIRS": [],
63+
"APP_DIRS": True,
64+
"OPTIONS": {
65+
"context_processors": [
66+
"django.template.context_processors.debug",
67+
"django.template.context_processors.request",
68+
"django.contrib.auth.context_processors.auth",
69+
"django.contrib.messages.context_processors.messages",
70+
],
71+
},
72+
},
73+
]
74+
75+
WSGI_APPLICATION = "user_auth_intro.wsgi.application"
76+
77+
78+
# Database
79+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
80+
81+
DATABASES = {
82+
"default": {
83+
"ENGINE": "django.db.backends.sqlite3",
84+
"NAME": BASE_DIR / "db.sqlite3",
85+
}
86+
}
87+
88+
89+
# Password validation
90+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
91+
92+
AUTH_PASSWORD_VALIDATORS = [
93+
{
94+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
95+
},
96+
{
97+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
98+
},
99+
{
100+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
101+
},
102+
{
103+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
104+
},
105+
]
106+
107+
108+
# Internationalization
109+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
110+
111+
LANGUAGE_CODE = "en-us"
112+
113+
TIME_ZONE = "UTC"
114+
115+
USE_I18N = True
116+
117+
USE_TZ = True
118+
119+
120+
# Static files (CSS, JavaScript, Images)
121+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
122+
123+
STATIC_URL = "static/"
124+
125+
# Default primary key field type
126+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
127+
128+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

0 commit comments

Comments
 (0)