@@ -61,7 +61,7 @@ def quickstart_get_collection():
61
61
docs = users_ref .stream ()
62
62
63
63
for doc in docs :
64
- print (u'{ } => {}' . format ( doc .id , doc . to_dict ()) )
64
+ print (f' { doc . id } => { doc .to_dict ()} ' )
65
65
# [END quickstart_get_collection]
66
66
67
67
@@ -149,9 +149,14 @@ def to_dict(self):
149
149
150
150
def __repr__ (self ):
151
151
return (
152
- u'City(name={}, country={}, population={}, capital={}, regions={})'
153
- .format (self .name , self .country , self .population , self .capital ,
154
- self .regions ))
152
+ f'City(\
153
+ name={ self .name } , \
154
+ country={ self .country } , \
155
+ population={ self .population } , \
156
+ capital={ self .capital } , \
157
+ regions={ self .regions } \
158
+ )'
159
+ )
155
160
# [END custom_class_def]
156
161
157
162
@@ -219,7 +224,7 @@ def get_check_exists():
219
224
220
225
doc = doc_ref .get ()
221
226
if doc .exists :
222
- print (u 'Document data: {}' . format ( doc .to_dict ()) )
227
+ print (f 'Document data: { doc .to_dict ()} ' )
223
228
else :
224
229
print (u'No such document!' )
225
230
# [END get_check_exists]
@@ -242,7 +247,7 @@ def get_simple_query():
242
247
docs = db .collection (u'cities' ).where (u'capital' , u'==' , True ).stream ()
243
248
244
249
for doc in docs :
245
- print (u'{ } => {}' . format ( doc .id , doc . to_dict ()) )
250
+ print (f' { doc . id } => { doc .to_dict ()} ' )
246
251
# [END get_simple_query]
247
252
248
253
@@ -255,7 +260,7 @@ def array_contains_filter():
255
260
# [END fs_array_contains_filter]
256
261
docs = query .stream ()
257
262
for doc in docs :
258
- print (u'{ } => {}' . format ( doc .id , doc . to_dict ()) )
263
+ print (f' { doc . id } => { doc .to_dict ()} ' )
259
264
260
265
261
266
def get_full_collection ():
@@ -264,7 +269,7 @@ def get_full_collection():
264
269
docs = db .collection (u'cities' ).stream ()
265
270
266
271
for doc in docs :
267
- print (u'{ } => {}' . format ( doc .id , doc . to_dict ()) )
272
+ print (f' { doc . id } => { doc .to_dict ()} ' )
268
273
# [END get_full_collection]
269
274
270
275
@@ -332,7 +337,7 @@ def update_doc_array():
332
337
city_ref .update ({u'regions' : firestore .ArrayRemove ([u'east_coast' ])})
333
338
# [END fs_update_doc_array]
334
339
city = city_ref .get ()
335
- print (u 'Updated the regions field of the DC. {}' . format ( city .to_dict ()) )
340
+ print (f 'Updated the regions field of the DC. { city .to_dict ()} ' )
336
341
337
342
338
343
def update_multiple ():
@@ -622,7 +627,7 @@ def snapshot_cursors():
622
627
# [END fs_start_at_snapshot_query_cursor]
623
628
results = start_at_snapshot .limit (10 ).stream ()
624
629
for doc in results :
625
- print (u'{}' . format ( doc .id ) )
630
+ print (f' { doc .id } ' )
626
631
627
632
return results
628
633
@@ -667,7 +672,7 @@ def listen_document():
667
672
# Create a callback on_snapshot function to capture changes
668
673
def on_snapshot (doc_snapshot , changes , read_time ):
669
674
for doc in doc_snapshot :
670
- print (u 'Received document snapshot: {}' . format ( doc .id ) )
675
+ print (f 'Received document snapshot: { doc .id } ' )
671
676
callback_done .set ()
672
677
673
678
doc_ref = db .collection (u'cities' ).document (u'SF' )
@@ -705,7 +710,7 @@ def on_snapshot(col_snapshot, changes, read_time):
705
710
print (u'Callback received query snapshot.' )
706
711
print (u'Current cities in California:' )
707
712
for doc in col_snapshot :
708
- print (u'{}' . format ( doc .id ) )
713
+ print (f' { doc .id } ' )
709
714
callback_done .set ()
710
715
711
716
col_query = db .collection (u'cities' ).where (u'state' , u'==' , u'CA' )
@@ -741,11 +746,11 @@ def on_snapshot(col_snapshot, changes, read_time):
741
746
print (u'Current cities in California: ' )
742
747
for change in changes :
743
748
if change .type .name == 'ADDED' :
744
- print (u 'New city: {}' . format ( change .document .id ) )
749
+ print (f 'New city: { change .document .id } ' )
745
750
elif change .type .name == 'MODIFIED' :
746
- print (u 'Modified city: {}' . format ( change .document .id ) )
751
+ print (f 'Modified city: { change .document .id } ' )
747
752
elif change .type .name == 'REMOVED' :
748
- print (u 'Removed city: {}' . format ( change .document .id ) )
753
+ print (f 'Removed city: { change .document .id } ' )
749
754
delete_done .set ()
750
755
751
756
col_query = db .collection (u'cities' ).where (u'state' , u'==' , u'CA' )
@@ -835,7 +840,7 @@ def delete_collection(coll_ref, batch_size):
835
840
deleted = 0
836
841
837
842
for doc in docs :
838
- print (u 'Deleting doc {} => {}' . format ( doc .id , doc . to_dict ()) )
843
+ print (f 'Deleting doc { doc . id } => { doc .to_dict ()} ' )
839
844
doc .reference .delete ()
840
845
deleted = deleted + 1
841
846
@@ -905,7 +910,7 @@ def collection_group_query(db):
905
910
.where (u'type' , u'==' , u'museum' )
906
911
docs = museums .stream ()
907
912
for doc in docs :
908
- print (u'{ } => {}' . format ( doc .id , doc . to_dict ()) )
913
+ print (f' { doc . id } => { doc .to_dict ()} ' )
909
914
# [END fs_collection_group_query]
910
915
return docs
911
916
0 commit comments