We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cfda284 commit 38b58a9Copy full SHA for 38b58a9
docs/builtin/open.md
@@ -19,9 +19,19 @@ Python open() built-in function
19
## Examples
20
21
```python
22
-f = open("some_file.txt", "r")
23
-```
+>>> spam = open('spam.txt', mode='x')
+>>> spam.write('My first line\n\n')
24
+>>> spam.close()
25
+# Opens a brand new file (in 'x' mode will throw if already exists)
26
+
27
+>>> with open('spam.txt', mode='a') as spam:
28
+... spam.write('My second line')
29
+# Appends to file and automatically closes afterward
30
-<!-- remove this tag to start editing this page -->
-<empty-section />
31
+>>> with open('spam.txt') as spam:
32
+... content = spam.read()
33
+... print(content)
34
+# My first line
35
+#
36
+# My second line
37
+```
0 commit comments