X Tutup
Skip to content

Commit a8c42b0

Browse files
authored
Update 33_country_code1.py
1 parent 79341d9 commit a8c42b0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

scripts/33_country_code.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,67 @@ def write_data(array_of_arrays):
4949
json_file_name = sys.argv[2]
5050
data = get_data(csv_file_name, json_file_name)
5151
write_data(data)
52+
53+
54+
import csv, json
55+
56+
57+
with open("33_country_codes.json","r") as file:
58+
data=json.load(file)
59+
print(data)
60+
61+
62+
63+
64+
65+
66+
67+
68+
codes = {"country": [
69+
{
70+
"countryCode": "AD",
71+
"countryName": "Andorra",
72+
"continentName": "Europe"
73+
},
74+
{
75+
"countryCode": "AE",
76+
"countryName": "United Arab Emirates",
77+
"continentName": "Asia"
78+
},
79+
{
80+
"countryCode": "AF",
81+
"countryName": "Afghanistan",
82+
"continentName": "Asia"
83+
}
84+
]
85+
}
86+
87+
codesc=[]
88+
countries=[]
89+
continrnt=[]
90+
91+
92+
print(codes["country"][0]["countryName"])
93+
94+
for code in data["country"]:
95+
codesc.append(code["countryCode"])
96+
countries.append(code["countryName"])
97+
continrnt.append(code["continentName"])
98+
99+
100+
101+
print(codesc)
102+
print(countries)
103+
print(continrnt)
104+
105+
106+
def save_csv(codesc, countries, continrnt):
107+
with open("myCSV1.csv", "w", newline="") as file:
108+
writer=csv.writer(file)
109+
writer.writerow(["country Code","country Name","continent Name"])
110+
print(codesc,countries,continrnt)
111+
for i in range(1,len(countries)):
112+
writer.writerow([codesc[i],countries[i],continrnt[i]])
113+
114+
115+
save_csv(codesc,countries,continrnt)

0 commit comments

Comments
 (0)
X Tutup