File tree Expand file tree Collapse file tree 4 files changed +52
-0
lines changed
Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ # Python 3.12 Preview: Ever Better Error Messages
2+
3+ This repository contains script files with code examples shown in the Real Python tutorial [ Python 3.12 Preview: Ever Better Error Messages] ( https://realpython.com/python312-error-messages/ ) .
4+
5+ The examples support the tutorial text.
6+
Original file line number Diff line number Diff line change 1+ from this import d
2+
3+ message = "Gunaxf sbe nyy gur nqqrq pynevgl va reebe zrffntrf, Cnoyb!"
4+
5+ decoded_message = ""
6+ for character in message :
7+ if character .isalpha ():
8+ decoded_message += d .get (character , "" )
9+ else :
10+ decoded_message += character
11+
12+ print (decoded_message )
Original file line number Diff line number Diff line change 1+ from this import d
2+
3+ message = "Thanks for all the added clarity in error messages, Pablo!"
4+
5+ reverse_cypher_dict = {value : key for key , value in d .items ()}
6+
7+ encoded_message = ""
8+ for character in message :
9+ if character .isalpha ():
10+ encoded_message += reverse_cypher_dict .get (character , "" )
11+ else :
12+ encoded_message += character
13+
14+ print (encoded_message )
Original file line number Diff line number Diff line change 1+ import inspect
2+
3+
4+ class Greeter :
5+ def __init__ (self ):
6+ self .message = "Hello"
7+
8+ def greet (self , whom = "World" ):
9+ frame = inspect .currentframe ()
10+ wrong_name = "message"
11+
12+ if "self" in frame .f_locals :
13+ self = frame .f_locals ["self" ]
14+ if hasattr (self , wrong_name ):
15+ raise NameError (
16+ f"name '{ wrong_name } ' is not defined. Did you mean: 'self.{ wrong_name } '?"
17+ )
18+
19+
20+ Greeter ().greet ()
You can’t perform that action at this time.
0 commit comments