summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--python.html.markdown8
1 files changed, 4 insertions, 4 deletions
diff --git a/python.html.markdown b/python.html.markdown
index 0bd16a80..e46d726e 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -492,19 +492,19 @@ with open("myfile.txt") as f:
# Writing to a file
contents = {"aa": 12, "bb": 21}
-with open("myfile1.txt", "w+") as file:
+with open("myfile1.txt", "w") as file:
file.write(str(contents)) # writes a string to a file
-with open("myfile2.txt", "w+") as file:
+with open("myfile2.txt", "w") as file:
file.write(json.dumps(contents)) # writes an object to a file
# Reading from a file
-with open('myfile1.txt', "r+") as file:
+with open('myfile1.txt', "r") as file:
contents = file.read() # reads a string from a file
print(contents)
# print: {"aa": 12, "bb": 21}
-with open('myfile2.txt', "r+") as file:
+with open('myfile2.txt', "r") as file:
contents = json.load(file) # reads a json object from a file
print(contents)
# print: {"aa": 12, "bb": 21}