text file and JSON .ipynb - Colab
text file and JSON .ipynb - Colab
ipynb - Colab
f=open("D:\textfile.txt",'w')
f.write("first line\n")
f.write('Second line\n')
f.write("third line\n")
f.close()
k=open("/content/D: extfile.txt",'r')
print(k.readline())
print(k.readline())
print(k.readline())
k.close()
first line
Second line
third line
m=open("/content/D: extfile.txt",'a')
m.write("fourth line\n")
m.write("fifth line\n")
m.close()
p=open("/content/D: extfile.txt",'r')
print(p.read())
p.close()
first line
Second line
third line
fourth line
fifth line
['first line\n', 'Second line\n', 'third line\n', 'fourth line\n', 'fifth line\n']
import json
x ='{"name":"John","age":30,"city":"New York"}'
y=json.loads(x)
print(y["age"])
30
x
{
"name":"John",
"age":30,
"city":"New York"
}
y=json.dumps(x)
print(y)
"{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}"
https://colab.research.google.com/drive/1NXassKHR8HSVRiGh_pQJMANJQE7dWgG_#scrollTo=SaektmUR8XYd&printMode=true 1/2