-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into python-parallel-processing
- Loading branch information
Showing
56 changed files
with
356 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.