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
""" | |
hollyandprosper.com | |
YouTube Channel: https://www.youtube.com/@hollyandprosper | |
Link to the original YouTube Short: | |
part 1: https://youtu.be/642mFCjpHxA | |
part 2: https://youtu.be/VFGaapH0gaQ | |
part 3: https://youtu.be/k0ekMw6u5wU | |
""" |
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
with open('example.txt', 'r') as file: | |
# do something |
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
""" | |
hollyandprosper.com | |
YouTube Channel: https://www.youtube.com/@hollyandprosper | |
Link to the original YouTube Short: https://youtu.be/Oo2g93efAeQ | |
""" | |
alpha = 'alpha' | |
# alpha[0] = 'A' |
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
""" | |
hollyandprosper.com | |
YouTube Channel: https://www.youtube.com/@hollyandprosper | |
Link to the original YouTube Short: https://youtu.be/rnAl4Rk5bu8 | |
""" | |
from immutabledict import immutabledict | |
immu_dict_a = immutabledict({ | |
'alpha': 1, | |
'beta': 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
""" | |
hollyandprosper.com | |
YouTube Channel: https://www.youtube.com/@hollyandprosper | |
Link to the original YouTube Short: https://youtu.be/lATMth5wb1E | |
""" | |
# wrong way | |
def add_tourist(tourist, tourist_list=[]): | |
tourist_list.append(tourist) |
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
class Coach: | |
def warm_up_players(self): | |
print("The coach is warming up the players.") | |
def host_retro_meeting(self): | |
print("The coach is having a retro meeting after the game.") | |
def coach_game(self): | |
print("The game is in progress.") |
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
from typing import Callable | |
class Coach: | |
def warm_up_players(self): | |
print("The coach is warming up the players.") | |
def host_retro_meeting(self): | |
print("The coach is having a retro meeting after the game.") | |
def coach_game(self): |
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
from contextlib import contextmanager | |
from coach import Coach | |
@contextmanager | |
def activity_management(coach: Coach): | |
try: | |
coach.warm_up_players() | |
yield coach | |
finally: | |
coach.host_retro_meeting() |
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
from contextlib import contextmanager | |
@contextmanager | |
def open_file(path, mode): | |
try: | |
file = open(path, mode) | |
yield file | |
finally: | |
file.close() |
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
from coach import Coach | |
class ActivityManagedCoach(Coach): | |
def __enter__(self): | |
self.warm_up_players() | |
return self | |
def __exit__(self, exc_type, exc_val, exc_tb): | |
self.host_retro_meeting() | |
print(f"Exception type: {exc_type}") |
OlderNewer