[{"data":1,"prerenderedAt":367},["ShallowReactive",2],{"tag-labels":3,"site-header":4,"article-python-file-read-write-id":75},{},{"featuredPost":5,"navigations":29},{"id":6,"title":7,"title_id":8,"slug":9,"excerpt":10,"excerpt_id":11,"has_translation":12,"published_at":13,"reading_time":14,"hidden_from_listing":15,"tags":16,"thumbnail_image":21,"og_image":22,"series":23,"authors":28},110,"When You Pick a Framework Just to Look Different","Ketika Pilih Framework Cuma Biar Kelihatan Beda","ketika-pilih-framework-cuma-biar-kelihatan-beda","The last time you chose a new framework or library, was it because your problem needed that tool, or because it sounded cool and few people around you were using it? That question is uncomfortable. Technology decisions are often made for reasons that never appear in any technical document.","Terakhir kali kamu milih framework atau library baru, itu karena masalahmu butuh alat itu, atau karena alatnya kedengaran keren dan belum banyak yang pakai? Pertanyaan ini nggak enak dijawab. Soalnya keputusan teknologi sering diambil dengan alasan yang nggak pernah ditulis di dokumen teknis mana pun.",true,"2026-10-06T15:25:21.000Z",5,false,[17,18,19,20],"karier","framework","opini","pengalaman",null,"\u002Fog\u002Fketika-pilih-framework-cuma-biar-kelihatan-beda.png",{"id":24,"title":25,"title_id":26,"slug":27},9,"Articles","Artikel","all",[],[30,49,70],{"collection":31,"item":32},"series",{"__typename":31,"title":25,"title_id":26,"slug":27,"children_series":33},[34,38,42,46],{"title":35,"title_id":36,"slug":37},"Artificial Intelligence","Kecerdasan Artifisial","kecerdasan-artifisial",{"title":39,"title_id":40,"slug":41},"Programming Fundamentals","Konsep Dasar Pemrograman","konsep-dasar-pemrograman",{"title":43,"title_id":44,"slug":45},"Algorithms and Data Structures","Algoritma dan Struktur Data","algoritma-struktur-data",{"title":47,"title_id":47,"slug":48},"LLM Systems","llm-systems",{"collection":31,"item":50},{"__typename":31,"title":51,"title_id":51,"slug":52,"children_series":53},"Tutorial","tutorial",[54,58,62,66],{"title":55,"title_id":56,"slug":57},"Learning Python","Belajar Python","belajar-python",{"title":59,"title_id":60,"slug":61},"Learning Go","Belajar Golang","belajar-golang",{"title":63,"title_id":64,"slug":65},"Learning Java","Belajar Java","belajar-java",{"title":67,"title_id":68,"slug":69},"Learning Pascal","Belajar Pascal","belajar-pascal",{"collection":31,"item":71},{"__typename":31,"title":72,"title_id":72,"slug":73,"children_series":74},"Lab","lab",[],{"article":76,"renderedBody":255,"renderedTakeaway":256,"latestArticles":257,"toc":350},{"id":77,"title":78,"title_id":78,"slug":79,"excerpt":80,"excerpt_id":80,"has_translation":12,"published_at":81,"reading_time":82,"hidden_from_listing":15,"tags":83,"thumbnail_image":21,"og_image":86,"series":87,"authors":247,"seoTitle":21,"seoDescription":21,"body_locale":250,"available_locales":251,"body":253,"takeway":254,"prerequisite":21},162,"Python File I\u002FO: Kenapa Pembacaan Kedua Kembali Kosong","python-file-read-write","Skrip catatan menyimpan satu baris, mencetaknya kembali, lalu menghitung nol. Berkas di disk sudah benar: `read()` meninggalkan pointer di ujung, jadi panggilan kedua mengembalikan string kosong. Baca sekali ke sebuah variabel, atau `seek(0)`, dan hitungannya cocok dengan berkas.","2026-11-20T01:00:00.000Z",6,[84,85],"python","input-output","\u002Fog\u002Fpython-file-read-write.png",{"id":88,"title":89,"title_id":90,"slug":91,"description":92,"description_id":93,"articles":94,"children_series":216,"parent_series":217},18,"Working with Python Scripts","Menggunakan Script Python","python-pemrograman-dengan-script","Leave the interpreter and start writing real .py files, including how to take input and print output.","Keluar dari interpreter dan mulai nulis file .py sendiri, lengkap dengan cara mengambil input dan menampilkan output.",[95,116,131,147,163,178,193,209],{"id":96,"title":97,"title_id":98,"slug":99,"excerpt":100,"excerpt_id":101,"has_translation":12,"published_at":102,"reading_time":103,"hidden_from_listing":15,"tags":104,"thumbnail_image":21,"og_image":107,"series":108,"authors":109},90,"Writing and Running a Python Script","Menulis dan Menjalankan Script Python","menulis-dan-menjalankan-script-python","A Python script is a file holding Python code, and it usually carries the .py extension.","Script python merupakan file berisi kode dengan bahasa Python yang biasanya memiliki ekstensi .py","2021-03-21T14:49:24.000Z",4,[84,52,105,106],"tooling","cli","\u002Fog\u002Fmenulis-dan-menjalankan-script-python.png",{"id":88,"title":89,"title_id":90,"slug":91},[110],{"authors_id":111},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},1,"Daffa Izzuddin","izzudd","Writer",{"id":117,"title":118,"title_id":119,"slug":120,"excerpt":121,"excerpt_id":122,"has_translation":12,"published_at":123,"reading_time":103,"hidden_from_listing":15,"tags":124,"thumbnail_image":21,"og_image":126,"series":127,"authors":128},91,"Input and Output Systems in Python 3","Sistem Input dan Output pada Python 3","sistem-input-dan-output-pada-python-3","A few functions, print() and input() among them, are the standard tools most I\u002FO work in Python is built on.","Beberapa fungsi seperti print() dan input(), merupakan fungsi standar yang banyak digunakan untuk melakukan I\u002FO.","2021-05-19T14:57:25.000Z",[84,85,125],"dasar","\u002Fog\u002Fsistem-input-dan-output-pada-python-3.png",{"id":88,"title":89,"title_id":90,"slug":91},[129],{"authors_id":130},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":132,"title":133,"title_id":134,"slug":135,"excerpt":136,"excerpt_id":137,"has_translation":12,"published_at":138,"reading_time":139,"hidden_from_listing":15,"tags":140,"thumbnail_image":21,"og_image":142,"series":143,"authors":144},136,"Python Modules: the Import That Printed the Report","Modul Python: Import yang Mencetak Laporannya","python-modules","You pull one function out into its own file, import it, and the whole report runs again and eats your input. A module is a file, `import` runs it top to bottom, and one line decides which of the two jobs it is doing.","Kamu memindahkan satu fungsi ke file sendiri, meng-import-nya, dan seluruh laporan jalan lagi lalu memakan inputmu. Modul adalah file, `import` menjalankannya dari atas ke bawah, dan satu baris menentukan pekerjaan mana yang sedang dijalankan file itu.","2026-11-06T01:00:00.000Z",7,[84,141],"modules","\u002Fog\u002Fpython-modules.png",{"id":88,"title":89,"title_id":90,"slug":91},[145],{"authors_id":146},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":148,"title":149,"title_id":150,"slug":151,"excerpt":152,"excerpt_id":153,"has_translation":12,"published_at":154,"reading_time":14,"hidden_from_listing":15,"tags":155,"thumbnail_image":21,"og_image":158,"series":159,"authors":160},138,"Python venv: the Install That Went Into the Wrong Python","venv Python: Instalasi yang Masuk ke Python yang Salah","python-venv-pip","`pip install` printed Successfully installed, and the next run raised ModuleNotFoundError on the same machine. Two interpreters, one install, and the variable your script checks is the one the interpreter never sets.","`pip install` mencetak Successfully installed, lalu jalan berikutnya melempar ModuleNotFoundError di mesin yang sama. Dua interpreter, satu instalasi, dan variabel yang skripmu periksa justru tidak pernah dipasang oleh interpreter.","2026-11-07T12:00:00.000Z",[84,156,157],"venv","pip","\u002Fog\u002Fpython-venv-pip.png",{"id":88,"title":89,"title_id":90,"slug":91},[161],{"authors_id":162},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":164,"title":165,"title_id":166,"slug":167,"excerpt":168,"excerpt_id":169,"has_translation":12,"published_at":170,"reading_time":139,"hidden_from_listing":15,"tags":171,"thumbnail_image":21,"og_image":173,"series":174,"authors":175},143,"Python stdlib: the datetime json.dumps Refused to Write","Python stdlib: datetime yang Ditolak json.dumps","python-stdlib","A script that totals minutes per day dies on the line that writes the report. Four stdlib modules carry it, and one TypeError stands in the way.","Skrip yang menjumlahkan menit per hari mati tepat di baris yang menulis laporan. Empat modul stdlib membawanya, dan satu TypeError menghadang.","2026-11-08T01:00:00.000Z",[84,172,106],"stdlib","\u002Fog\u002Fpython-stdlib.png",{"id":88,"title":89,"title_id":90,"slug":91},[176],{"authors_id":177},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":179,"title":180,"title_id":181,"slug":182,"excerpt":183,"excerpt_id":184,"has_translation":12,"published_at":185,"reading_time":139,"hidden_from_listing":15,"tags":186,"thumbnail_image":21,"og_image":188,"series":189,"authors":190},144,"Python debugging: the script that exits 0 with the wrong total","Debugging Python: skrip keluar dengan kode 0, tapi totalnya salah","python-debugging","A totals script runs clean, prints a number, and the number is wrong. With no traceback to follow, you stop the program at the line that writes the value and read the dict from pdb.","Skrip penjumlah berjalan mulus, mencetak angka, dan angkanya salah. Tanpa traceback untuk diikuti, kamu menghentikan program di baris yang menulis nilai itu lalu membaca isi dict dari pdb.","2026-11-09T01:00:00.000Z",[84,187],"debugging","\u002Fog\u002Fpython-debugging.png",{"id":88,"title":89,"title_id":90,"slug":91},[191],{"authors_id":192},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":194,"title":195,"title_id":196,"slug":197,"excerpt":198,"excerpt_id":199,"has_translation":12,"published_at":200,"reading_time":14,"hidden_from_listing":15,"tags":201,"thumbnail_image":21,"og_image":204,"series":205,"authors":206},157,"Python try\u002Fexcept\u002Ffinally: Handling a Blank CSV Cell Without Losing the Total","Python try\u002Fexcept\u002Ffinally: Sel CSV Kosong yang Menghapus Total Laporan","python-try-except-finally","A minutes total dies on one empty CSV cell and prints nothing, so the rows that parsed fine are lost with it. Wrapping the conversion in `try` with `except ValueError` skips the bad row, and `finally` prints the summary even when the file is missing.","Total menit mati karena satu sel CSV kosong dan tidak mencetak apa pun, jadi baris yang berhasil dibaca ikut hilang bersamanya. Membungkus konversinya dengan `try` dan `except ValueError` melewati baris rusak itu, dan `finally` tetap mencetak ringkasan meski berkasnya tidak ada.","2026-11-16T01:00:00.000Z",[84,202,203],"error-handling","exception","\u002Fog\u002Fpython-try-except-finally.png",{"id":88,"title":89,"title_id":90,"slug":91},[207],{"authors_id":208},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":77,"title":210,"title_id":78,"slug":79,"excerpt":211,"excerpt_id":80,"has_translation":12,"published_at":81,"reading_time":82,"hidden_from_listing":15,"tags":83,"thumbnail_image":21,"og_image":86,"series":212,"authors":213},"Python File I\u002FO: Why the Second Read Came Back Empty","A notes script saves a line, prints it back, then counts zero. The file on disk is correct: `read()` left the pointer at the end, so the second call returned an empty string. Read once into a variable, or `seek(0)`, and the count matches the file.",{"id":88,"title":89,"title_id":90,"slug":91},[214],{"authors_id":215},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},[],{"id":218,"title":55,"title_id":56,"slug":57,"parent_series":219,"children_series":220},10,{"id":112,"title":51,"title_id":51,"slug":52},[221,226,231,232,237,242],{"id":222,"title":223,"title_id":224,"slug":225,"cover_image":21},16,"Getting Started with Python","Berkenalan dengan Bahasa Python","python-intro",{"id":227,"title":228,"title_id":229,"slug":230,"cover_image":21},17,"Variables, Types, and Operations","Variabel, Tipe Data, dan Operasi","python-variabel-tipe-data",{"id":88,"title":89,"title_id":90,"slug":91,"cover_image":21},{"id":233,"title":234,"title_id":235,"slug":236,"cover_image":21},19,"Control Structures","Struktur Kontrol","python-struktur-kontrol",{"id":238,"title":239,"title_id":240,"slug":241,"cover_image":21},20,"Functional Programming with Python","Pemrograman Fungsional dengan Python","python-pemrograman-fungsional",{"id":243,"title":244,"title_id":245,"slug":246,"cover_image":21},30,"Collections and Strings","Koleksi dan String","python-collections",[248],{"authors_id":249},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},"id",[252,250],"en","\nSkrip catatan menyimpan satu baris, mencetaknya kembali, lalu menghitung baris di dalam berkas. Ia mencetak catatannya, lalu `jumlah baris: 0`. Berkas di disk berisi catatan itu, dan programnya keluar dengan status 0, jadi tidak ada yang tampak rusak.\n\n## Hitungan yang bilang nol\n\nSimpan ini sebagai `notes.py`. Skrip ini menambahkan catatan yang kamu berikan di baris perintah, lalu membuka berkasnya untuk menampilkannya dan menghitung baris.\n\n```python\n# notes.py\nimport sys\n\npath = sys.argv[1]\nnote = sys.argv[2]\n\nwith open(path, \"a\") as handle:\n    handle.write(note + \"\\n\")\n\nhandle = open(path)\nprint(\"catatan tersimpan:\")\nprint(handle.read(), end=\"\")\nprint(\"jumlah baris:\", len(handle.read().splitlines()))\n```\n\nJalankan sekali pada berkas yang belum ada.\n\n```text\n$ python3 notes.py notes.txt \"beli kopi\"\ncatatan tersimpan:\nbeli kopi\njumlah baris: 0\n```\n\nCatatannya tercetak, tapi hitungannya tidak cocok. `cat notes.txt` menunjukkan barisnya benar-benar tertulis, jadi penulisannya berhasil dan pembacaan yang kedua itulah yang salah.\n\n## Berkasnya baik-baik saja; pointernya tidak\n\n`open()` memberimu handle dengan sebuah posisi, dan `read()` memindahkan posisi itu ke ujung berkas. Setelah catatan pertama, `notes.txt` berisi sepuluh byte, jadi pointer-nya duduk di byte 10. `read()` berikutnya mulai dari sana, tidak menemukan byte tersisa, dan mengembalikan string kosong alih-alih error.\n\n`notes.py` memanggil `handle.read()` dua kali pada handle yang sama. Panggilan pertama ada di dalam `print(handle.read(), end=\"\")` dan mengembalikan catatannya. Panggilan kedua ada di dalam `len(handle.read().splitlines())` dan mulai dari ujung tanpa sisa yang bisa dibaca. `len(\"\".splitlines())` bernilai 0, dan skripnya mencetak 0 tanpa error. Tidak ada exception yang dilempar, jadi status keluar tetap 0.\n\n## Checker-nya\n\n`check_notes.py` menjalankan `notes.py` tiga kali pada satu berkas di folder sementara, sekali per catatan, jadi berkasnya semestinya berisi satu baris, lalu dua, lalu tiga. Setelah jalan pertama ia membuka berkasnya sendiri dan membandingkan isinya dengan `beli kopi\\n`, jadi pemeriksaan itu tidak pernah bergantung pada apa yang dicetak skripnya. Pemeriksaan lain mencari `jumlah baris: 1`, `jumlah baris: 2`, dan `jumlah baris: 3` di keluarannya. Saat pemeriksaan hitungan gagal, ia mencetak baris terakhir keluaran itu setelah `\u003C-`, jadi kamu melihat angka yang dilaporkan skripnya.\n\n```python\n# check_notes.py\nimport os\nimport subprocess\nimport sys\nimport tempfile\n\nHERE = os.path.dirname(os.path.abspath(__file__))\nSUBJECT = os.path.join(HERE, \"notes.py\")\n\npassed = 0\nfailed = 0\n\n\ndef check(label, condition, detail=\"\"):\n    global passed, failed\n    if condition:\n        passed += 1\n        print(f\"PASS  {label}\")\n    else:\n        failed += 1\n        print(f\"FAIL  {label}\" + (f\"  \u003C- {detail}\" if detail else \"\"))\n\n\ndef run(path, note):\n    return subprocess.run(\n        [sys.executable, SUBJECT, path, note],\n        capture_output=True,\n        text=True,\n    )\n\n\ndef last_line(text):\n    lines = text.strip().splitlines()\n    return lines[-1] if lines else \"(no output)\"\n\n\nwith tempfile.TemporaryDirectory() as folder:\n    path = os.path.join(folder, \"notes.txt\")\n\n    first = run(path, \"beli kopi\")\n    check(\"the script exits without an error\", first.returncode == 0, last_line(first.stderr))\n    with open(path) as handle:\n        isi = handle.read()\n    check(\"the first note reaches the file\", isi == \"beli kopi\\n\", repr(isi))\n    check(\"it prints the note it just saved\", \"beli kopi\" in first.stdout)\n    check(\"it counts one line\", \"jumlah baris: 1\" in first.stdout, last_line(first.stdout))\n\n    second = run(path, \"telepon ibu\")\n    check(\"the second run keeps the first note\", \"beli kopi\" in second.stdout)\n    check(\"it counts two lines\", \"jumlah baris: 2\" in second.stdout, last_line(second.stdout))\n\n    third = run(path, \"bayar listrik\")\n    check(\"it counts three lines\", \"jumlah baris: 3\" in third.stdout, last_line(third.stdout))\n\nprint()\nprint(f\"{passed} of {passed + failed} checks passed\")\nsys.exit(1 if failed else 0)\n```\n\nVersi awal gagal tiga pemeriksaan dan lolos empat.\n\n```text\n$ python3 check_notes.py\nPASS  the script exits without an error\nPASS  the first note reaches the file\nPASS  it prints the note it just saved\nFAIL  it counts one line  \u003C- jumlah baris: 0\nPASS  the second run keeps the first note\nFAIL  it counts two lines  \u003C- jumlah baris: 0\nFAIL  it counts three lines  \u003C- jumlah baris: 0\n\n4 of 7 checks passed\n```\n\nEmpat yang lolos mencakup status keluar, isi berkas, dan catatan yang muncul di kedua jalan. Status keluar 0 hanya berarti Python tidak crash; tiga pemeriksaan hitungan tetap gagal dengan `\u003C- jumlah baris: 0` karena hitungan itulah satu-satunya keluaran yang dibangun dari `read()` kedua.\n\n## Baca sekali, lalu hitung\n\nBaca berkasnya ke sebuah variabel, lalu hitung variabelnya.\n\n```python\n# notes.py\nimport sys\n\npath = sys.argv[1]\nnote = sys.argv[2]\n\nwith open(path, \"a\") as handle:\n    handle.write(note + \"\\n\")\n\nwith open(path) as handle:\n    isi = handle.read()\n\nprint(\"catatan tersimpan:\")\nprint(isi, end=\"\")\nprint(\"jumlah baris:\", len(isi.splitlines()))\n```\n\nDua jalan sekarang cocok dengan berkasnya.\n\n```text\n$ python3 notes.py notes.txt \"beli kopi\"\ncatatan tersimpan:\nbeli kopi\njumlah baris: 1\n$ python3 notes.py notes.txt \"telepon ibu\"\ncatatan tersimpan:\nbeli kopi\ntelepon ibu\njumlah baris: 2\n```\n\nChecker-nya hijau. Hitungannya sekarang datang dari `isi`, string yang sudah kamu baca, jadi tidak ada `read()` kedua yang bisa kembali kosong.\n\n```text\n$ python3 check_notes.py\nPASS  the script exits without an error\nPASS  the first note reaches the file\nPASS  it prints the note it just saved\nPASS  it counts one line\nPASS  the second run keeps the first note\nPASS  it counts two lines\nPASS  it counts three lines\n\n7 of 7 checks passed\n```\n\n`handle.seek(0)` sebelum pembacaan kedua melakukan hal yang sama pada satu handle: ia mengirim pointer kembali ke awal. Membaca sekali lebih pendek, jadi mulai dari situ.\n\n## Append bukan timpa\n\n`open(path, \"a\")` menambahkan di ujung dan membuat berkasnya kalau belum ada. `open(path, \"w\")` mengosongkannya dulu, lalu menulis dari awal.\n\nGanti `\"a\"` di salinanmu jadi `\"w\"` dan jalankan checker-nya lagi. Kamu dapat `4 of 7 checks passed`. Jalan kedua tidak lagi menampilkan catatan pertama, dan hitungan untuk dua serta tiga baris gagal. Hitungannya terbaca 1 di setiap jalan, karena berkasnya hanya pernah berisi baris yang baru kamu tulis. Tidak ada yang melempar error, dan catatan sebelumnya tertimpa.\n","- `read()` memindahkan pointer berkas ke ujung, jadi `read()` kedua pada handle yang sama mengembalikan `''` dan setiap hitungan yang dibangun di atasnya bernilai nol.\n- Berkas di disk tidak apa-apa: `tell()` melaporkan 5 setelah membaca berkas 5 byte, dan dari situlah pembacaan berikutnya mulai.\n- Baca sekali ke sebuah variabel lalu hitung variabel itu, atau panggil `seek(0)` untuk mengembalikan pointer ke awal.\n- `open(path, \"a\")` menambahkan di ujung dan membuat berkasnya kalau belum ada, sementara `\"w\"` mengosongkannya sebelum menulis, jadi mode menentukan apakah catatan kemarin bertahan.","\u003Cp>Skrip catatan menyimpan satu baris, mencetaknya kembali, lalu menghitung baris di dalam berkas. Ia mencetak catatannya, lalu \u003Ccode>jumlah baris: 0\u003C\u002Fcode>. Berkas di disk berisi catatan itu, dan programnya keluar dengan status 0, jadi tidak ada yang tampak rusak.\u003C\u002Fp>\n\u003Ch2 id=\"hitungan-yang-bilang-nol\">Hitungan yang bilang nol\u003C\u002Fh2>\n\u003Cp>Simpan ini sebagai \u003Ccode>notes.py\u003C\u002Fcode>. Skrip ini menambahkan catatan yang kamu berikan di baris perintah, lalu membuka berkasnya untuk menampilkannya dan menghitung baris.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%23%20notes.py%0Aimport%20sys%0A%0Apath%20%3D%20sys.argv%5B1%5D%0Anote%20%3D%20sys.argv%5B2%5D%0A%0Awith%20open(path%2C%20%22a%22)%20as%20handle%3A%0A%20%20%20%20handle.write(note%20%2B%20%22%5Cn%22)%0A%0Ahandle%20%3D%20open(path)%0Aprint(%22catatan%20tersimpan%3A%22)%0Aprint(handle.read()%2C%20end%3D%22%22)%0Aprint(%22jumlah%20baris%3A%22%2C%20len(handle.read().splitlines()))\" title=\"Salin\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Salin\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#6A737D\"># notes.py\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> sys\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">path \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> sys.argv[\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">1\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">]\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">note \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> sys.argv[\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">2\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">]\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">with\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> open\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(path, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"a\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">as\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> handle:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    handle.write(note \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">handle \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> open\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(path)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"catatan tersimpan:\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(handle.read(), \u003C\u002Fspan>\u003Cspan style=\"color:#FFAB70\">end\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"jumlah baris:\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(handle.read().splitlines()))\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Jalankan sekali pada berkas yang belum ada.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">TEXT\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20python3%20notes.py%20notes.txt%20%22beli%20kopi%22%0Acatatan%20tersimpan%3A%0Abeli%20kopi%0Ajumlah%20baris%3A%200\" title=\"Salin\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Salin\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>$ python3 notes.py notes.txt \"beli kopi\"\ncatatan tersimpan:\nbeli kopi\njumlah baris: 0\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Catatannya tercetak, tapi hitungannya tidak cocok. \u003Ccode>cat notes.txt\u003C\u002Fcode> menunjukkan barisnya benar-benar tertulis, jadi penulisannya berhasil dan pembacaan yang kedua itulah yang salah.\u003C\u002Fp>\n\u003Ch2 id=\"berkasnya-baik-baik-saja-pointernya-tidak\">Berkasnya baik-baik saja; pointernya tidak\u003C\u002Fh2>\n\u003Cp>\u003Ccode>open()\u003C\u002Fcode> memberimu handle dengan sebuah posisi, dan \u003Ccode>read()\u003C\u002Fcode> memindahkan posisi itu ke ujung berkas. Setelah catatan pertama, \u003Ccode>notes.txt\u003C\u002Fcode> berisi sepuluh byte, jadi pointer-nya duduk di byte 10. \u003Ccode>read()\u003C\u002Fcode> berikutnya mulai dari sana, tidak menemukan byte tersisa, dan mengembalikan string kosong alih-alih error.\u003C\u002Fp>\n\u003Cp>\u003Ccode>notes.py\u003C\u002Fcode> memanggil \u003Ccode>handle.read()\u003C\u002Fcode> dua kali pada handle yang sama. Panggilan pertama ada di dalam \u003Ccode>print(handle.read(), end=&quot;&quot;)\u003C\u002Fcode> dan mengembalikan catatannya. Panggilan kedua ada di dalam \u003Ccode>len(handle.read().splitlines())\u003C\u002Fcode> dan mulai dari ujung tanpa sisa yang bisa dibaca. \u003Ccode>len(&quot;&quot;.splitlines())\u003C\u002Fcode> bernilai 0, dan skripnya mencetak 0 tanpa error. Tidak ada exception yang dilempar, jadi status keluar tetap 0.\u003C\u002Fp>\n\u003Ch2 id=\"checker-nya\">Checker-nya\u003C\u002Fh2>\n\u003Cp>\u003Ccode>check_notes.py\u003C\u002Fcode> menjalankan \u003Ccode>notes.py\u003C\u002Fcode> tiga kali pada satu berkas di folder sementara, sekali per catatan, jadi berkasnya semestinya berisi satu baris, lalu dua, lalu tiga. Setelah jalan pertama ia membuka berkasnya sendiri dan membandingkan isinya dengan \u003Ccode>beli kopi\\n\u003C\u002Fcode>, jadi pemeriksaan itu tidak pernah bergantung pada apa yang dicetak skripnya. Pemeriksaan lain mencari \u003Ccode>jumlah baris: 1\u003C\u002Fcode>, \u003Ccode>jumlah baris: 2\u003C\u002Fcode>, dan \u003Ccode>jumlah baris: 3\u003C\u002Fcode> di keluarannya. Saat pemeriksaan hitungan gagal, ia mencetak baris terakhir keluaran itu setelah \u003Ccode>&lt;-\u003C\u002Fcode>, jadi kamu melihat angka yang dilaporkan skripnya.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%23%20check_notes.py%0Aimport%20os%0Aimport%20subprocess%0Aimport%20sys%0Aimport%20tempfile%0A%0AHERE%20%3D%20os.path.dirname(os.path.abspath(__file__))%0ASUBJECT%20%3D%20os.path.join(HERE%2C%20%22notes.py%22)%0A%0Apassed%20%3D%200%0Afailed%20%3D%200%0A%0A%0Adef%20check(label%2C%20condition%2C%20detail%3D%22%22)%3A%0A%20%20%20%20global%20passed%2C%20failed%0A%20%20%20%20if%20condition%3A%0A%20%20%20%20%20%20%20%20passed%20%2B%3D%201%0A%20%20%20%20%20%20%20%20print(f%22PASS%20%20%7Blabel%7D%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20failed%20%2B%3D%201%0A%20%20%20%20%20%20%20%20print(f%22FAIL%20%20%7Blabel%7D%22%20%2B%20(f%22%20%20%3C-%20%7Bdetail%7D%22%20if%20detail%20else%20%22%22))%0A%0A%0Adef%20run(path%2C%20note)%3A%0A%20%20%20%20return%20subprocess.run(%0A%20%20%20%20%20%20%20%20%5Bsys.executable%2C%20SUBJECT%2C%20path%2C%20note%5D%2C%0A%20%20%20%20%20%20%20%20capture_output%3DTrue%2C%0A%20%20%20%20%20%20%20%20text%3DTrue%2C%0A%20%20%20%20)%0A%0A%0Adef%20last_line(text)%3A%0A%20%20%20%20lines%20%3D%20text.strip().splitlines()%0A%20%20%20%20return%20lines%5B-1%5D%20if%20lines%20else%20%22(no%20output)%22%0A%0A%0Awith%20tempfile.TemporaryDirectory()%20as%20folder%3A%0A%20%20%20%20path%20%3D%20os.path.join(folder%2C%20%22notes.txt%22)%0A%0A%20%20%20%20first%20%3D%20run(path%2C%20%22beli%20kopi%22)%0A%20%20%20%20check(%22the%20script%20exits%20without%20an%20error%22%2C%20first.returncode%20%3D%3D%200%2C%20last_line(first.stderr))%0A%20%20%20%20with%20open(path)%20as%20handle%3A%0A%20%20%20%20%20%20%20%20isi%20%3D%20handle.read()%0A%20%20%20%20check(%22the%20first%20note%20reaches%20the%20file%22%2C%20isi%20%3D%3D%20%22beli%20kopi%5Cn%22%2C%20repr(isi))%0A%20%20%20%20check(%22it%20prints%20the%20note%20it%20just%20saved%22%2C%20%22beli%20kopi%22%20in%20first.stdout)%0A%20%20%20%20check(%22it%20counts%20one%20line%22%2C%20%22jumlah%20baris%3A%201%22%20in%20first.stdout%2C%20last_line(first.stdout))%0A%0A%20%20%20%20second%20%3D%20run(path%2C%20%22telepon%20ibu%22)%0A%20%20%20%20check(%22the%20second%20run%20keeps%20the%20first%20note%22%2C%20%22beli%20kopi%22%20in%20second.stdout)%0A%20%20%20%20check(%22it%20counts%20two%20lines%22%2C%20%22jumlah%20baris%3A%202%22%20in%20second.stdout%2C%20last_line(second.stdout))%0A%0A%20%20%20%20third%20%3D%20run(path%2C%20%22bayar%20listrik%22)%0A%20%20%20%20check(%22it%20counts%20three%20lines%22%2C%20%22jumlah%20baris%3A%203%22%20in%20third.stdout%2C%20last_line(third.stdout))%0A%0Aprint()%0Aprint(f%22%7Bpassed%7D%20of%20%7Bpassed%20%2B%20failed%7D%20checks%20passed%22)%0Asys.exit(1%20if%20failed%20else%200)\" title=\"Salin\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Salin\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#6A737D\"># check_notes.py\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> os\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> subprocess\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> sys\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> tempfile\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">HERE\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> os.path.dirname(os.path.abspath(\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">__file__\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">SUBJECT\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> =\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> os.path.join(\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">HERE\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"notes.py\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">passed \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">failed \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">def\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> check\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(label, condition, detail\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">):\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    global\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> passed, failed\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    if\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> condition:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">        passed \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 1\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">        print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">f\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"PASS  \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">{\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">label\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">}\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    else\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">        failed \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 1\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">        print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">f\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"FAIL  \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">{\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">label\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">}\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> +\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> (\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">f\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"  &#x3C;- \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">{\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">detail\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">}\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> if\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> detail \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">else\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">def\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> run\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(path, note):\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    return\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> subprocess.run(\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">        [sys.executable, \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">SUBJECT\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, path, note],\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#FFAB70\">        capture_output\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">True\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#FFAB70\">        text\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">True\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    )\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">def\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> last_line\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(text):\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    lines \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> text.strip().splitlines()\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    return\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> lines[\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">-\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">1\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">] \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">if\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> lines \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">else\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"(no output)\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">with\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> tempfile.TemporaryDirectory() \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">as\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> folder:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    path \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> os.path.join(folder, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"notes.txt\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    first \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> run(path, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"beli kopi\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    check(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"the script exits without an error\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, first.returncode \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">==\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, last_line(first.stderr))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">    with\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> open\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(path) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">as\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> handle:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">        isi \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> handle.read()\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    check(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"the first note reaches the file\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, isi \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">==\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"beli kopi\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">repr\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(isi))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    check(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"it prints the note it just saved\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"beli kopi\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> in\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> first.stdout)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    check(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"it counts one line\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"jumlah baris: 1\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> in\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> first.stdout, last_line(first.stdout))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    second \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> run(path, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"telepon ibu\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    check(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"the second run keeps the first note\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"beli kopi\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> in\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> second.stdout)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    check(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"it counts two lines\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"jumlah baris: 2\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> in\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> second.stdout, last_line(second.stdout))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    third \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> run(path, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"bayar listrik\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    check(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"it counts three lines\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"jumlah baris: 3\"\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> in\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> third.stdout, last_line(third.stdout))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">()\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">f\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">{\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">passed\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">}\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> of \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">{\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">passed \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> failed\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">}\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> checks passed\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">sys.exit(\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">1\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> if\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> failed \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">else\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Versi awal gagal tiga pemeriksaan dan lolos empat.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">TEXT\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20python3%20check_notes.py%0APASS%20%20the%20script%20exits%20without%20an%20error%0APASS%20%20the%20first%20note%20reaches%20the%20file%0APASS%20%20it%20prints%20the%20note%20it%20just%20saved%0AFAIL%20%20it%20counts%20one%20line%20%20%3C-%20jumlah%20baris%3A%200%0APASS%20%20the%20second%20run%20keeps%20the%20first%20note%0AFAIL%20%20it%20counts%20two%20lines%20%20%3C-%20jumlah%20baris%3A%200%0AFAIL%20%20it%20counts%20three%20lines%20%20%3C-%20jumlah%20baris%3A%200%0A%0A4%20of%207%20checks%20passed\" title=\"Salin\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Salin\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>$ python3 check_notes.py\nPASS  the script exits without an error\nPASS  the first note reaches the file\nPASS  it prints the note it just saved\nFAIL  it counts one line  &lt;- jumlah baris: 0\nPASS  the second run keeps the first note\nFAIL  it counts two lines  &lt;- jumlah baris: 0\nFAIL  it counts three lines  &lt;- jumlah baris: 0\n\n4 of 7 checks passed\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Empat yang lolos mencakup status keluar, isi berkas, dan catatan yang muncul di kedua jalan. Status keluar 0 hanya berarti Python tidak crash; tiga pemeriksaan hitungan tetap gagal dengan \u003Ccode>&lt;- jumlah baris: 0\u003C\u002Fcode> karena hitungan itulah satu-satunya keluaran yang dibangun dari \u003Ccode>read()\u003C\u002Fcode> kedua.\u003C\u002Fp>\n\u003Ch2 id=\"baca-sekali-lalu-hitung\">Baca sekali, lalu hitung\u003C\u002Fh2>\n\u003Cp>Baca berkasnya ke sebuah variabel, lalu hitung variabelnya.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">PYTHON\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%23%20notes.py%0Aimport%20sys%0A%0Apath%20%3D%20sys.argv%5B1%5D%0Anote%20%3D%20sys.argv%5B2%5D%0A%0Awith%20open(path%2C%20%22a%22)%20as%20handle%3A%0A%20%20%20%20handle.write(note%20%2B%20%22%5Cn%22)%0A%0Awith%20open(path)%20as%20handle%3A%0A%20%20%20%20isi%20%3D%20handle.read()%0A%0Aprint(%22catatan%20tersimpan%3A%22)%0Aprint(isi%2C%20end%3D%22%22)%0Aprint(%22jumlah%20baris%3A%22%2C%20len(isi.splitlines()))\" title=\"Salin\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Salin\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#6A737D\"># notes.py\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> sys\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">path \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> sys.argv[\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">1\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">]\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">note \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> sys.argv[\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">2\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">]\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">with\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> open\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(path, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"a\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">as\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> handle:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    handle.write(note \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">with\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> open\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(path) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">as\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> handle:\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">    isi \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> handle.read()\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"catatan tersimpan:\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(isi, \u003C\u002Fspan>\u003Cspan style=\"color:#FFAB70\">end\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#79B8FF\">print\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"jumlah baris:\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(isi.splitlines()))\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Dua jalan sekarang cocok dengan berkasnya.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">TEXT\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20python3%20notes.py%20notes.txt%20%22beli%20kopi%22%0Acatatan%20tersimpan%3A%0Abeli%20kopi%0Ajumlah%20baris%3A%201%0A%24%20python3%20notes.py%20notes.txt%20%22telepon%20ibu%22%0Acatatan%20tersimpan%3A%0Abeli%20kopi%0Atelepon%20ibu%0Ajumlah%20baris%3A%202\" title=\"Salin\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Salin\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>$ python3 notes.py notes.txt \"beli kopi\"\ncatatan tersimpan:\nbeli kopi\njumlah baris: 1\n$ python3 notes.py notes.txt \"telepon ibu\"\ncatatan tersimpan:\nbeli kopi\ntelepon ibu\njumlah baris: 2\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Checker-nya hijau. Hitungannya sekarang datang dari \u003Ccode>isi\u003C\u002Fcode>, string yang sudah kamu baca, jadi tidak ada \u003Ccode>read()\u003C\u002Fcode> kedua yang bisa kembali kosong.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">TEXT\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20python3%20check_notes.py%0APASS%20%20the%20script%20exits%20without%20an%20error%0APASS%20%20the%20first%20note%20reaches%20the%20file%0APASS%20%20it%20prints%20the%20note%20it%20just%20saved%0APASS%20%20it%20counts%20one%20line%0APASS%20%20the%20second%20run%20keeps%20the%20first%20note%0APASS%20%20it%20counts%20two%20lines%0APASS%20%20it%20counts%20three%20lines%0A%0A7%20of%207%20checks%20passed\" title=\"Salin\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Salin\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>$ python3 check_notes.py\nPASS  the script exits without an error\nPASS  the first note reaches the file\nPASS  it prints the note it just saved\nPASS  it counts one line\nPASS  the second run keeps the first note\nPASS  it counts two lines\nPASS  it counts three lines\n\n7 of 7 checks passed\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>\u003Ccode>handle.seek(0)\u003C\u002Fcode> sebelum pembacaan kedua melakukan hal yang sama pada satu handle: ia mengirim pointer kembali ke awal. Membaca sekali lebih pendek, jadi mulai dari situ.\u003C\u002Fp>\n\u003Ch2 id=\"append-bukan-timpa\">Append bukan timpa\u003C\u002Fh2>\n\u003Cp>\u003Ccode>open(path, &quot;a&quot;)\u003C\u002Fcode> menambahkan di ujung dan membuat berkasnya kalau belum ada. \u003Ccode>open(path, &quot;w&quot;)\u003C\u002Fcode> mengosongkannya dulu, lalu menulis dari awal.\u003C\u002Fp>\n\u003Cp>Ganti \u003Ccode>&quot;a&quot;\u003C\u002Fcode> di salinanmu jadi \u003Ccode>&quot;w&quot;\u003C\u002Fcode> dan jalankan checker-nya lagi. Kamu dapat \u003Ccode>4 of 7 checks passed\u003C\u002Fcode>. Jalan kedua tidak lagi menampilkan catatan pertama, dan hitungan untuk dua serta tiga baris gagal. Hitungannya terbaca 1 di setiap jalan, karena berkasnya hanya pernah berisi baris yang baru kamu tulis. Tidak ada yang melempar error, dan catatan sebelumnya tertimpa.\u003C\u002Fp>\n","\u003Cul>\n\u003Cli>\u003Ccode>read()\u003C\u002Fcode> memindahkan pointer berkas ke ujung, jadi \u003Ccode>read()\u003C\u002Fcode> kedua pada handle yang sama mengembalikan \u003Ccode>&#39;&#39;\u003C\u002Fcode> dan setiap hitungan yang dibangun di atasnya bernilai nol.\u003C\u002Fli>\n\u003Cli>Berkas di disk tidak apa-apa: \u003Ccode>tell()\u003C\u002Fcode> melaporkan 5 setelah membaca berkas 5 byte, dan dari situlah pembacaan berikutnya mulai.\u003C\u002Fli>\n\u003Cli>Baca sekali ke sebuah variabel lalu hitung variabel itu, atau panggil \u003Ccode>seek(0)\u003C\u002Fcode> untuk mengembalikan pointer ke awal.\u003C\u002Fli>\n\u003Cli>\u003Ccode>open(path, &quot;a&quot;)\u003C\u002Fcode> menambahkan di ujung dan membuat berkasnya kalau belum ada, sementara \u003Ccode>&quot;w&quot;\u003C\u002Fcode> mengosongkannya sebelum menulis, jadi mode menentukan apakah catatan kemarin bertahan.\u003C\u002Fli>\n\u003C\u002Ful>\n",[258,273,294,312,317,336],{"id":259,"title":260,"title_id":261,"slug":262,"excerpt":263,"excerpt_id":264,"has_translation":12,"published_at":265,"reading_time":266,"hidden_from_listing":15,"tags":267,"thumbnail_image":21,"og_image":268,"series":269,"authors":270},164,"Python Capstone: Why a Blank CSV Field Cut the Class Average","Python Capstone: Kenapa Satu Kolom CSV Kosong Memotong Rata-rata Kelas","python-capstone-gradebook","A gradebook reads four students and writes a JSON report. The class average says 52.42, because two empty fields became zeros.","Buku nilai membaca empat siswa dan menulis laporan JSON. Rata-rata kelasnya bilang 52.42, karena dua kolom kosong berubah jadi nol.","2026-11-21T01:00:00.000Z",8,[84,85,106],"\u002Fog\u002Fpython-capstone-gradebook.png",{"id":218,"title":55,"title_id":56,"slug":57},[271],{"authors_id":272},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":274,"title":275,"title_id":276,"slug":277,"excerpt":278,"excerpt_id":279,"has_translation":12,"published_at":265,"reading_time":103,"hidden_from_listing":15,"tags":280,"thumbnail_image":21,"og_image":285,"series":286,"authors":291},48,"What a Linked List Actually Is","Tentang Struktur Data LinkedList","tentang-struktur-data-linked-list","A linked list is a linear chain of nodes, each holding data and a pointer to the next node. Here is what that chain looks like, what it costs next to an array, and the same minimal implementation in Java, Python, and JavaScript.","Linked list adalah rantai linear berisi node, dan setiap node menyimpan data plus pointer ke node berikutnya. Ini bentuk rantainya, ongkosnya dibanding array, dan implementasi paling sederhana dalam Java, Python, serta JavaScript.",[281,282,283,284],"struktur-data","linked-list","pointer","konsep","\u002Fog\u002Ftentang-struktur-data-linked-list.png",{"id":287,"title":288,"title_id":289,"slug":290},28,"Linear Data Structures","Struktur Data Linear","asd-struktur-linear",[292],{"authors_id":293},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":295,"title":296,"title_id":297,"slug":298,"excerpt":299,"excerpt_id":300,"has_translation":12,"published_at":81,"reading_time":82,"hidden_from_listing":15,"tags":301,"thumbnail_image":21,"og_image":306,"series":307,"authors":309},163,"Pascal Capstone: Why Every Gradebook Score Came Back Zero","Capstone Pascal: Kenapa Semua Skor Buku Nilai Kembali Nol","pascal-gradebook-capstone","A gradebook reads three students from a file, prints three rows, and every score is 0. The procedure filled a copy of the array, because the parameter was missing `var`. Add the word and the report matches the file; the compiler had already warned about the call that filled nothing.","Sebuah buku nilai membaca tiga siswa dari berkas, mencetak tiga baris, dan setiap skornya 0. Prosedurnya mengisi salinan array, karena parameternya kehilangan `var`. Tambahkan kata itu dan laporannya cocok dengan berkasnya; kompilator sudah memperingatkan soal pemanggilan yang tidak mengisi apa pun.",[302,303,304,305],"pascal","record","array","prosedur","\u002Fog\u002Fpascal-gradebook-capstone.png",{"id":308,"title":67,"title_id":68,"slug":69},14,[310],{"authors_id":311},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":77,"title":210,"title_id":78,"slug":79,"excerpt":211,"excerpt_id":80,"has_translation":12,"published_at":81,"reading_time":82,"hidden_from_listing":15,"tags":83,"thumbnail_image":21,"og_image":86,"series":313,"authors":314},{"id":88,"title":89,"title_id":90,"slug":91},[315],{"authors_id":316},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":318,"title":319,"title_id":320,"slug":321,"excerpt":322,"excerpt_id":323,"has_translation":12,"published_at":324,"reading_time":139,"hidden_from_listing":15,"tags":325,"thumbnail_image":21,"og_image":327,"series":328,"authors":333},47,"Why Understanding Algorithms and Data Structures Actually Matters","Pentingnya Memahami Algoritma dan Struktur Data","pentingnya-memahami-algoritma-dan-struktur-data","An algorithm is an ordered list of steps, and that order decides how expensive a problem is. The examples are on the back of an instant noodle packet, in a factorial, and behind ctrl+z.","Sebagai konsep fundamental, algoritma menentukan seberapa mahal sebuah masalah diselesaikan. Contohnya ada di bungkus mie instan, di bilangan faktorial, dan di tombol undo.","2026-11-19T01:00:00.000Z",[326,281,284,125],"algoritma","\u002Fog\u002Fpentingnya-memahami-algoritma-dan-struktur-data.png",{"id":329,"title":330,"title_id":331,"slug":332},27,"About Algorithms and Data Structures","Tentang Algoritma dan Struktur Data","asd-intro",[334],{"authors_id":335},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},{"id":337,"title":338,"title_id":339,"slug":340,"excerpt":341,"excerpt_id":342,"has_translation":12,"published_at":343,"reading_time":139,"hidden_from_listing":15,"tags":344,"thumbnail_image":21,"og_image":345,"series":346,"authors":347},161,"Debugging Free Pascal with -gl and gdb","Men-debug Free Pascal dengan -gl dan gdb","pascal-debugging-fpc-gdb","A run with no prices ends at a hex address and status 217. `-gl` names the line, gdb names the values, and the mean of six positive prices comes out negative because `integer` is 2 bytes.","Jalan tanpa satu harga pun berakhir di alamat hex dan status 217. `-gl` menyebut barisnya, gdb menyebut nilainya, dan rata-rata dari enam harga positif keluar negatif karena `integer` berukuran 2 byte.","2026-11-18T01:00:00.000Z",[302,187],"\u002Fog\u002Fpascal-debugging-fpc-gdb.png",{"id":308,"title":67,"title_id":68,"slug":69},[348],{"authors_id":349},{"id":112,"name":113,"slug":114,"role":115,"profile_picture":21},[351,355,358,361,364],{"text":352,"depth":353,"id":354},"Hitungan yang bilang nol",2,"hitungan-yang-bilang-nol",{"text":356,"depth":353,"id":357},"Berkasnya baik-baik saja; pointernya tidak","berkasnya-baik-baik-saja-pointernya-tidak",{"text":359,"depth":353,"id":360},"Checker-nya","checker-nya",{"text":362,"depth":353,"id":363},"Baca sekali, lalu hitung","baca-sekali-lalu-hitung",{"text":365,"depth":353,"id":366},"Append bukan timpa","append-bukan-timpa",1795825297494]