Skip to content

Commit 186b8d6

Browse files
committed
Modified the code to use "f string" string formatting.
1 parent 4eaa012 commit 186b8d6

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

flask-connexion-rest-part-3/notes.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def read_one(person_id, note_id):
5050

5151
# Otherwise, nope, didn't find that note
5252
else:
53-
abort(404, "Note not found for Id: {note_id}".format(note_id=note_id))
53+
abort(404, f"Note not found for Id: {note_id}")
5454

5555

5656
def create(person_id, note):
@@ -66,10 +66,7 @@ def create(person_id, note):
6666

6767
# Was a person found?
6868
if person is None:
69-
abort(
70-
404,
71-
"Person not found for Id: {person_id}".format(person_id=person_id),
72-
)
69+
abort(404, f"Person not found for Id: {person_id}")
7370

7471
# Create a note schema instance
7572
schema = NoteSchema()
@@ -123,7 +120,7 @@ def update(person_id, note_id, note):
123120

124121
# Otherwise, nope, didn't find that note
125122
else:
126-
abort(404, "Note not found for Id: {note_id}".format(note_id=note_id))
123+
abort(404, f"Note not found for Id: {note_id}")
127124

128125

129126
def delete(person_id, note_id):
@@ -151,4 +148,4 @@ def delete(person_id, note_id):
151148

152149
# Otherwise, nope, didn't find that note
153150
else:
154-
abort(404, "Note not found for Id: {note_id}".format(note_id=note_id))
151+
abort(404, f"Note not found for Id: {note_id}")

flask-connexion-rest-part-3/people.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ def read_one(person_id):
4949

5050
# Otherwise, nope, didn't find that person
5151
else:
52-
abort(
53-
404,
54-
"Person not found for Id: {person_id}".format(person_id=person_id),
55-
)
52+
abort(404, f"Person not found for Id: {person_id}")
5653

5754

5855
def create(person):
@@ -90,12 +87,7 @@ def create(person):
9087

9188
# Otherwise, nope, person exists already
9289
else:
93-
abort(
94-
409,
95-
"Person {fname} {lname} exists already".format(
96-
fname=fname, lname=lname
97-
),
98-
)
90+
abort(409, f"Person {fname} {lname} exists already")
9991

10092

10193
def update(person_id, person):
@@ -132,10 +124,7 @@ def update(person_id, person):
132124

133125
# Otherwise, nope, didn't find that person
134126
else:
135-
abort(
136-
404,
137-
"Person not found for Id: {person_id}".format(person_id=person_id),
138-
)
127+
abort(404, f"Person not found for Id: {person_id}")
139128

140129

141130
def delete(person_id):
@@ -152,13 +141,8 @@ def delete(person_id):
152141
if person is not None:
153142
db.session.delete(person)
154143
db.session.commit()
155-
return make_response(
156-
"Person {person_id} deleted".format(person_id=person_id), 200
157-
)
144+
return make_response(f"Person {person_id} deleted", 200)
158145

159146
# Otherwise, nope, didn't find that person
160147
else:
161-
abort(
162-
404,
163-
"Person not found for Id: {person_id}".format(person_id=person_id),
164-
)
148+
abort(404, f"Person not found for Id: {person_id}")

0 commit comments

Comments
 (0)