# Buku "Python untuk GIS", Bab 9: Catatan dan Laporan: Berkas dan Merakit Teks
# Skrip yang dibedah: ekspor ke CSV di b2_07
import csv

petak = [["P-01", 4.0], ["P-02", 8.0], ["P-03", 2.5]]
with open("petak.csv", "w", newline="", encoding="utf-8") as fh:
    w = csv.writer(fh)
    w.writerow(["KODE", "LUAS_HA"])
    for p in petak:
        w.writerow(p)

total = 0
with open("petak.csv", encoding="utf-8") as fh:
    pembaca = csv.reader(fh)
    next(pembaca)
    for baris in pembaca:
        total = total + float(baris[1])
print("Total luas:", total, "ha")
