File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -83,22 +83,20 @@ Write BSON to a File
83
83
84
84
To write BSON data to a file, open a file stream in write-binary mode on the output file.
85
85
Then, write each document to the output file. Ensure that documents are encoded in BSON
86
- format by using the ``BSON .encode()`` method.
86
+ format by using the ``bson .encode()`` method.
87
87
88
88
The following example writes the sample BSON document to ``file.bson``:
89
89
90
90
.. code-block:: python
91
91
92
- import bson
93
-
94
92
with open("file.bson", "w") as file:
95
- file.write(BSON .encode(document))
93
+ file.write(bson .encode(document))
96
94
97
95
Read BSON from a File
98
96
---------------------
99
97
100
98
To read BSON documents from a file, open a file stream in read-binary mode on the input
101
- file. Then, decode the documents from BSON format as you read them by using the ``BSON .decode()``
99
+ file. Then, decode the documents from BSON format as you read them by using the ``bson .decode()``
102
100
method.
103
101
104
102
The following example reads the sample BSON document from ``file.bson``:
@@ -111,7 +109,7 @@ The following example reads the sample BSON document from ``file.bson``:
111
109
112
110
with open("file.bson", "rb") as file:
113
111
data = file.read()
114
- document = BSON(data) .decode()
112
+ document = bson .decode(data )
115
113
print(document)
116
114
117
115
.. output::
You can’t perform that action at this time.
0 commit comments