greeneggs = """\
Green Eggs And Ham
I am Sam
I am Sam
Sam I am
That Sam-I-am
That Sam-I-am!
I do not like
That Sam-I-am
Do you like
Green eggs and ham
I do not like them
Sam-I-am
I do not like
Green eggs and ham
Would you like them
Here or there?
I would not like them
Here or there
I would not like them
Anywhere
I do not like
Green eggs and ham
I do not like them
Sam-I-am
"""
fout = open("green.txt", "w")
print(greeneggs, file=fout)
fout.close()
f = open("green.txt")
for line in f:
print(line)
csv = """\
name, age, money
david, 30, 1000
moshe, 25, 500
lea, 35, 50000
tamar, 29, 600"""
fout = open("csv.txt", "w")
print(csv, file=fout)
fout.close()
f = open("csv.txt")
column1, column2, *others = f.readline().split()
for line in f:
name, age, money = line.split()
print(f"name={name}, age={age}, money={money}")
others
with open("green.txt", "w") as fout:
print(greeneggs, file=fout)
print("here fout has been closed already")
dir(fout)
import sys
x = 0
if x == 0:
print("error", file=sys.stderr)
f = open("csv.txt")
#column1, column2, *others = f.readline().split()
for line in f:
name, age, money = line.split()
print(f"name={name}, age={age}, money={money}")
f.seek(3)
data = {
1: [],
2: [ {1: ["one"]}],
3: "blah",
4: [[[],[],[123]]]
}
fout = open("data.json.txt", "w")
import json
json.dump(data, fout, indent=1)
fout.close()
fin = open("data.json.txt")
dataout = json.load(fin)
dataout
{"1": [], "2": [{"1": ["one"]}], "3": "blah", "4": [[[], [], [123456]]]}
dataout == {"1": [], "2": [{"1": ["one"]}], "3": "blah", "4": [[[], [], [123456]]]}
help(json.dump)