Skip to content

Commit

Permalink
Merge branch 'master' into python-parallel-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
KateFinegan authored Sep 6, 2023
2 parents 52947ca + d2d6275 commit 552b35d
Show file tree
Hide file tree
Showing 56 changed files with 356 additions and 332 deletions.
3 changes: 3 additions & 0 deletions python-oop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Object-Oriented Programming (OOP) in Python 3

This folder provides the code examples for the Real Python tutorial [Object-Oriented Programming (OOP) in Python 3](https://realpython.com/object-oriented-programming-oop-in-python-3/).
14 changes: 14 additions & 0 deletions python-oop/cars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Car:
def __init__(self, color, mileage):
self.color = color
self.mileage = mileage

def __str__(self):
return f"The {self.color} car has {self.mileage:,} miles"


blue_car = Car(color="blue", mileage=20_000)
red_car = Car(color="red", mileage=30_000)

for car in (blue_car, red_car):
print(car)
12 changes: 12 additions & 0 deletions python-oop/dog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Dog:
species = "Canis familiaris"

def __init__(self, name, age):
self.name = name
self.age = age

def __str__(self):
return f"{self.name} is {self.age} years old"

def speak(self, sound):
return f"{self.name} says {sound}"
25 changes: 25 additions & 0 deletions python-oop/dogbreeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Dog:
species = "Canis familiaris"

def __init__(self, name, age):
self.name = name
self.age = age

def __str__(self):
return f"{self.name} is {self.age} years old"

def speak(self, sound):
return f"{self.name} barks: {sound}"


class JackRussellTerrier(Dog):
def speak(self, sound="Arf"):
return super().speak(sound)


class Dachshund(Dog):
pass


class Bulldog(Dog):
pass
17 changes: 17 additions & 0 deletions python-oop/retriever.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Dog:
species = "Canis familiaris"

def __init__(self, name, age):
self.name = name
self.age = age

def __str__(self):
return f"{self.name} is {self.age} years old"

def speak(self, sound):
return f"{self.name} says {sound}"


class GoldenRetriever(Dog):
def speak(self, sound="Bark"):
return super().speak(sound)
5 changes: 5 additions & 0 deletions python-oop/starfleet_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Starfleet employees as a list

kirk = ["James Kirk", 34, "Captain", 2265]
spock = ["Spock", 35, "Science Officer", 2254]
mccoy = ["Leonard McCoy", "Chief Medical Officer", 2266]
14 changes: 14 additions & 0 deletions python-oop/starfleet_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Starfleet employees as objects


class Employee:
def __init__(self, name, age, position, year_started):
self.name = name
self.age = age
self.position = position
self.year_started = year_started


kirk = Employee("James Kirk", 34, "Captain", 2265)
spock = Employee("Spock", 35, "Science Officer", 2254)
mccoy = Employee("Leonard McCoy", 137, "Chief Medical Officer", 2266)
10 changes: 10 additions & 0 deletions python-qr-code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generate Beautiful QR Codes With Python

Supporting code for the Real Python tutorial [Generate Beautiful QR Codes With Python](https://realpython.com/python-generate-qr-code/).

To run the code in this tutorial, you should have `segno`, `pillow`, and `qrcode-artistic` installed in your environment.
You can install with the command below:

```console
$ python -m pip install segno pillow qrcode-artistic
```
11 changes: 11 additions & 0 deletions python-qr-code/scripts/animated_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import segno
from urllib.request import urlopen

slts_qrcode = segno.make_qr("https://www.youtube.com/watch?v=hTWKbfoikeg")
nirvana_url = urlopen("https://media.giphy.com/media/LpwBqCorPvZC0/giphy.gif")
slts_qrcode.to_artistic(
background=nirvana_url,
target="animated_qrcode.gif",
light="blue",
scale=5,
)
4 changes: 4 additions & 0 deletions python-qr-code/scripts/basic_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import segno

qrcode = segno.make_qr("Hello, World")
qrcode.save("basic_qrcode.png")
4 changes: 4 additions & 0 deletions python-qr-code/scripts/borderless_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import segno

qrcode = segno.make_qr("Hello, World")
qrcode.save("borderless_qrcode.png", scale=5, border=0)
11 changes: 11 additions & 0 deletions python-qr-code/scripts/darkblue_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import segno

qrcode = segno.make_qr("Hello, World")

# Without changing the color of the quiet zone
qrcode.save("darkblue_qrcode.png", scale=5, dark="darkblue")

# With quiet zone
qrcode.save(
"darkblue_qrcode.png", scale=5, dark="darkblue", quiet_zone="maroon"
)
8 changes: 8 additions & 0 deletions python-qr-code/scripts/formatted_rotated_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import segno

qrcode = segno.make_qr("Hello, World")

qrcode_rotated = qrcode.to_pil(
scale=5, light="lightblue", dark="green"
).rotate(45, expand=True)
qrcode_rotated.save("formatted_rotated_qrcode.png")
22 changes: 22 additions & 0 deletions python-qr-code/scripts/green_datamodules_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import segno

qrcode = segno.make_qr("Hello, World")

# Changing the color of only the dark data modules
qrcode.save(
"green_datadark_qrcode.png",
scale=5,
light="lightblue",
dark="darkblue",
data_dark="green",
)

# Changing the color of the dark and light data modules
qrcode.save(
"green_datamodules_qrcode.png",
scale=5,
light="lightblue",
dark="darkblue",
data_dark="green",
data_light="lightgreen",
)
4 changes: 4 additions & 0 deletions python-qr-code/scripts/lightblue_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import segno

qrcode = segno.make_qr("Hello, World")
qrcode.save("lightblue_qrcode.png", light="lightblue", scale=5)
11 changes: 11 additions & 0 deletions python-qr-code/scripts/rotated_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import segno

qrcode = segno.make_qr("Hello, World")

# Rotated QR code but truncated
qrcode_rotated = qrcode.to_pil().rotate(45)
qrcode_rotated.save("rotated_qrcode.png")

# Setting expand to True
qrcode_rotated = qrcode.to_pil().rotate(45, expand=True)
qrcode_rotated.save("rotated_qrcode.png")
4 changes: 4 additions & 0 deletions python-qr-code/scripts/scaled_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import segno

qrcode = segno.make_qr("Hello, World")
qrcode.save("scaled_qrcode.png", scale=2)
4 changes: 4 additions & 0 deletions python-qr-code/scripts/wide_border_qrcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import segno

qrcode = segno.make_qr("Hello, World")
qrcode.save("wide_border_qrcode.png", scale=5, border=10)
44 changes: 44 additions & 0 deletions rp-portfolio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Get Started With Django: Build a Portfolio App

Follow the [step-by-step instructions](https://realpython.com/get-started-with-django-1/) on Real Python to build your own portfolio project with Django.

## Images

You can find the example images for the projects in the [uploads/project_images](uploads/project_images) folder.

## Setup

You can run the provided example project on your local machine by following the steps outlined below.

Create a new virtual environment:

```bash
$ python3 -m venv venv
```

Activate the virtual environment:

```bash
$ source venv/bin/activate
```

Install the dependencies for this project if you haven't installed them yet:

```bash
(venv) $ python -m pip install -r requirements.txt
```

Make and apply the migrations for the project to build your local database:

```bash
(venv) $ python manage.py makemigrations
(venv) $ python manage.py migrate
```

Run the Django development server:

```bash
(venv) $ python manage.py runserver
```

Navigate to `http://localhost:8000/` or `http://localhost:8000/projects` to see your portfolio project in action.
14 changes: 0 additions & 14 deletions rp-portfolio/blog/admin.py

This file was deleted.

5 changes: 0 additions & 5 deletions rp-portfolio/blog/apps.py

This file was deleted.

15 changes: 0 additions & 15 deletions rp-portfolio/blog/forms.py

This file was deleted.

54 changes: 0 additions & 54 deletions rp-portfolio/blog/migrations/0001_initial.py

This file was deleted.

Empty file.
20 changes: 0 additions & 20 deletions rp-portfolio/blog/models.py

This file was deleted.

20 changes: 0 additions & 20 deletions rp-portfolio/blog/templates/blog_category.html

This file was deleted.

Loading

0 comments on commit 552b35d

Please sign in to comment.