Skip to content

Commit

Permalink
数据存储json
Browse files Browse the repository at this point in the history
  • Loading branch information
wush committed Nov 24, 2019
1 parent a4c9874 commit 3120423
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/31_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json
filename="F:\\03学习区\\13Python\\02Demo\\python\\pi_digits.txt"
numbers=[1,2,3,4,5]

#存储数据json.dump()
with open(filename,'w') as file_object:
json.dump(numbers,file_object)

#读取数据json.load()
with open(filename) as file_object:
numbers2=json.load(file_object)
print(numbers2)
6 changes: 6 additions & 0 deletions python/31_json_greet_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import json
filename="F:\\03学习区\\13Python\\02Demo\\python\\pi_digits.txt"

with open(filename) as file_object:
username=json.load(file_object)
print("Wecom back " + username)
7 changes: 7 additions & 0 deletions python/31_json_remember.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import json
filename="F:\\03学习区\\13Python\\02Demo\\python\\pi_digits.txt"

username=input("What is your name?\n")
with open(filename,'w') as file_object:
json.dump(username,file_object)
print("We will remember you when you come back," + username)

0 comments on commit 3120423

Please sign in to comment.