[{"data":1,"prerenderedAt":367},["ShallowReactive",2],{"tag-labels":3,"site-header":4,"article-python-file-read-write-en":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":79,"slug":80,"excerpt":81,"excerpt_id":82,"has_translation":12,"published_at":83,"reading_time":84,"hidden_from_listing":15,"tags":85,"thumbnail_image":21,"og_image":88,"series":89,"authors":247,"seoTitle":21,"seoDescription":21,"body_locale":250,"available_locales":251,"body":253,"takeway":254,"prerequisite":21},162,"Python File I\u002FO: Why the Second Read Came Back Empty","Python File I\u002FO: Kenapa Pembacaan Kedua Kembali Kosong","python-file-read-write","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.","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,[86,87],"python","input-output","\u002Fog\u002Fpython-file-read-write.png",{"id":90,"title":91,"title_id":92,"slug":93,"description":94,"description_id":95,"articles":96,"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.",[97,118,133,149,165,180,195,211],{"id":98,"title":99,"title_id":100,"slug":101,"excerpt":102,"excerpt_id":103,"has_translation":12,"published_at":104,"reading_time":105,"hidden_from_listing":15,"tags":106,"thumbnail_image":21,"og_image":109,"series":110,"authors":111},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,[86,52,107,108],"tooling","cli","\u002Fog\u002Fmenulis-dan-menjalankan-script-python.png",{"id":90,"title":91,"title_id":92,"slug":93},[112],{"authors_id":113},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},1,"Daffa Izzuddin","izzudd","Writer",{"id":119,"title":120,"title_id":121,"slug":122,"excerpt":123,"excerpt_id":124,"has_translation":12,"published_at":125,"reading_time":105,"hidden_from_listing":15,"tags":126,"thumbnail_image":21,"og_image":128,"series":129,"authors":130},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",[86,87,127],"dasar","\u002Fog\u002Fsistem-input-dan-output-pada-python-3.png",{"id":90,"title":91,"title_id":92,"slug":93},[131],{"authors_id":132},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},{"id":134,"title":135,"title_id":136,"slug":137,"excerpt":138,"excerpt_id":139,"has_translation":12,"published_at":140,"reading_time":141,"hidden_from_listing":15,"tags":142,"thumbnail_image":21,"og_image":144,"series":145,"authors":146},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,[86,143],"modules","\u002Fog\u002Fpython-modules.png",{"id":90,"title":91,"title_id":92,"slug":93},[147],{"authors_id":148},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},{"id":150,"title":151,"title_id":152,"slug":153,"excerpt":154,"excerpt_id":155,"has_translation":12,"published_at":156,"reading_time":14,"hidden_from_listing":15,"tags":157,"thumbnail_image":21,"og_image":160,"series":161,"authors":162},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",[86,158,159],"venv","pip","\u002Fog\u002Fpython-venv-pip.png",{"id":90,"title":91,"title_id":92,"slug":93},[163],{"authors_id":164},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},{"id":166,"title":167,"title_id":168,"slug":169,"excerpt":170,"excerpt_id":171,"has_translation":12,"published_at":172,"reading_time":141,"hidden_from_listing":15,"tags":173,"thumbnail_image":21,"og_image":175,"series":176,"authors":177},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",[86,174,108],"stdlib","\u002Fog\u002Fpython-stdlib.png",{"id":90,"title":91,"title_id":92,"slug":93},[178],{"authors_id":179},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},{"id":181,"title":182,"title_id":183,"slug":184,"excerpt":185,"excerpt_id":186,"has_translation":12,"published_at":187,"reading_time":141,"hidden_from_listing":15,"tags":188,"thumbnail_image":21,"og_image":190,"series":191,"authors":192},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",[86,189],"debugging","\u002Fog\u002Fpython-debugging.png",{"id":90,"title":91,"title_id":92,"slug":93},[193],{"authors_id":194},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},{"id":196,"title":197,"title_id":198,"slug":199,"excerpt":200,"excerpt_id":201,"has_translation":12,"published_at":202,"reading_time":14,"hidden_from_listing":15,"tags":203,"thumbnail_image":21,"og_image":206,"series":207,"authors":208},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",[86,204,205],"error-handling","exception","\u002Fog\u002Fpython-try-except-finally.png",{"id":90,"title":91,"title_id":92,"slug":93},[209],{"authors_id":210},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},{"id":77,"title":78,"title_id":79,"slug":80,"excerpt":81,"excerpt_id":82,"has_translation":12,"published_at":83,"reading_time":84,"hidden_from_listing":15,"tags":85,"thumbnail_image":21,"og_image":88,"series":212,"authors":213},{"id":90,"title":91,"title_id":92,"slug":93},[214],{"authors_id":215},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},[],{"id":218,"title":55,"title_id":56,"slug":57,"parent_series":219,"children_series":220},10,{"id":114,"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":90,"title":91,"title_id":92,"slug":93,"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":114,"name":115,"slug":116,"role":117,"profile_picture":21},"en",[250,252],"id","\nA notes script saves one line, prints it back, and counts the lines in the file. It prints the note, then `jumlah baris: 0`. The file on disk contains the note, and the program exits with status 0, so nothing looks broken.\n\n## The count that says zero\n\nSave this as `notes.py`. It appends the note you pass on the command line, then opens the file to show it and count the lines.\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\nRun it once against a file that does not exist yet.\n\n```text\n$ python3 notes.py notes.txt \"beli kopi\"\ncatatan tersimpan:\nbeli kopi\njumlah baris: 0\n```\n\nThe note prints, but the count does not match it. `cat notes.txt` shows the line was written, so the write worked and the read is what came back wrong.\n\n## The file was fine; the pointer was not\n\n`open()` gives you a handle with a position, and `read()` moves that position to the end of the file. After the first note, `notes.txt` holds ten bytes, so the pointer sits at byte 10. The next `read()` starts there, finds no bytes left, and returns an empty string instead of an error.\n\n`notes.py` calls `handle.read()` twice on the same handle. The first call sits inside `print(handle.read(), end=\"\")` and returns the note. The second sits inside `len(handle.read().splitlines())` and starts at the end with nothing left to give. `len(\"\".splitlines())` is 0, and the script prints 0 with no error. No exception is raised, so the exit status stays 0.\n\n## The checker\n\n`check_notes.py` runs `notes.py` three times against one file in a temporary folder, once per note, so the file should hold one line, then two, then three. After the first run it opens the file itself and compares the contents with `beli kopi\\n`, so that check never depends on what the script prints. The other checks search the output for `jumlah baris: 1`, `jumlah baris: 2` and `jumlah baris: 3`. When a count check fails, it prints the last line of that output after `\u003C-`, so you see the number the script reported.\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\nThe starter fails three checks and passes four.\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\nThe four passes cover the exit status, the file contents, and the note appearing on both runs. Exit status 0 only means Python did not crash; the three count checks still fail with `\u003C- jumlah baris: 0` because the count is the only output built on the second `read()`.\n\n## Read once, then count\n\nRead the file into a variable, then count the variable.\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\nTwo runs now agree with the file.\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\nThe checker is green. The count now comes from `isi`, the string you already read, so no second `read()` is left to come back empty.\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)` before the second read does the same job on one handle: it sends the pointer back to the start. Reading once is shorter, so start there.\n\n## Append is not overwrite\n\n`open(path, \"a\")` adds at the end and creates the file when it is missing. `open(path, \"w\")` empties it first, then writes at the start.\n\nChange the `\"a\"` in your copy to `\"w\"` and run the checker again. You get `4 of 7 checks passed`. The second run no longer shows the first note, and the counts for two and three lines fail. The count reads 1 on every run, because the file only ever holds the line you just wrote. Nothing raised an error, and the earlier notes were overwritten.\n","- `read()` moves the file pointer to the end, so a second `read()` on the same handle returns `''` and every count built on it is zero.\n- The file on disk is fine: `tell()` reports 5 after reading a 5-byte file, which is where the next read starts.\n- Read once into a variable and count that, or call `seek(0)` to send the pointer back to the start.\n- `open(path, \"a\")` appends and creates the file when it is missing, while `\"w\"` empties it before writing, so the mode determines whether yesterday's notes survive.","\u003Cp>A notes script saves one line, prints it back, and counts the lines in the file. It prints the note, then \u003Ccode>jumlah baris: 0\u003C\u002Fcode>. The file on disk contains the note, and the program exits with status 0, so nothing looks broken.\u003C\u002Fp>\n\u003Ch2 id=\"the-count-that-says-zero\">The count that says zero\u003C\u002Fh2>\n\u003Cp>Save this as \u003Ccode>notes.py\u003C\u002Fcode>. It appends the note you pass on the command line, then opens the file to show it and count the lines.\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=\"Copy\">\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\">Copy\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>Run it once against a file that does not exist yet.\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=\"Copy\">\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\">Copy\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>The note prints, but the count does not match it. \u003Ccode>cat notes.txt\u003C\u002Fcode> shows the line was written, so the write worked and the read is what came back wrong.\u003C\u002Fp>\n\u003Ch2 id=\"the-file-was-fine-the-pointer-was-not\">The file was fine; the pointer was not\u003C\u002Fh2>\n\u003Cp>\u003Ccode>open()\u003C\u002Fcode> gives you a handle with a position, and \u003Ccode>read()\u003C\u002Fcode> moves that position to the end of the file. After the first note, \u003Ccode>notes.txt\u003C\u002Fcode> holds ten bytes, so the pointer sits at byte 10. The next \u003Ccode>read()\u003C\u002Fcode> starts there, finds no bytes left, and returns an empty string instead of an error.\u003C\u002Fp>\n\u003Cp>\u003Ccode>notes.py\u003C\u002Fcode> calls \u003Ccode>handle.read()\u003C\u002Fcode> twice on the same handle. The first call sits inside \u003Ccode>print(handle.read(), end=&quot;&quot;)\u003C\u002Fcode> and returns the note. The second sits inside \u003Ccode>len(handle.read().splitlines())\u003C\u002Fcode> and starts at the end with nothing left to give. \u003Ccode>len(&quot;&quot;.splitlines())\u003C\u002Fcode> is 0, and the script prints 0 with no error. No exception is raised, so the exit status stays 0.\u003C\u002Fp>\n\u003Ch2 id=\"the-checker\">The checker\u003C\u002Fh2>\n\u003Cp>\u003Ccode>check_notes.py\u003C\u002Fcode> runs \u003Ccode>notes.py\u003C\u002Fcode> three times against one file in a temporary folder, once per note, so the file should hold one line, then two, then three. After the first run it opens the file itself and compares the contents with \u003Ccode>beli kopi\\n\u003C\u002Fcode>, so that check never depends on what the script prints. The other checks search the output for \u003Ccode>jumlah baris: 1\u003C\u002Fcode>, \u003Ccode>jumlah baris: 2\u003C\u002Fcode> and \u003Ccode>jumlah baris: 3\u003C\u002Fcode>. When a count check fails, it prints the last line of that output after \u003Ccode>&lt;-\u003C\u002Fcode>, so you see the number the script reported.\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=\"Copy\">\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\">Copy\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>The starter fails three checks and passes four.\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=\"Copy\">\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\">Copy\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>The four passes cover the exit status, the file contents, and the note appearing on both runs. Exit status 0 only means Python did not crash; the three count checks still fail with \u003Ccode>&lt;- jumlah baris: 0\u003C\u002Fcode> because the count is the only output built on the second \u003Ccode>read()\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Ch2 id=\"read-once-then-count\">Read once, then count\u003C\u002Fh2>\n\u003Cp>Read the file into a variable, then count the variable.\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=\"Copy\">\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\">Copy\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>Two runs now agree with the file.\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=\"Copy\">\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\">Copy\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>The checker is green. The count now comes from \u003Ccode>isi\u003C\u002Fcode>, the string you already read, so no second \u003Ccode>read()\u003C\u002Fcode> is left to come back empty.\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=\"Copy\">\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\">Copy\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> before the second read does the same job on one handle: it sends the pointer back to the start. Reading once is shorter, so start there.\u003C\u002Fp>\n\u003Ch2 id=\"append-is-not-overwrite\">Append is not overwrite\u003C\u002Fh2>\n\u003Cp>\u003Ccode>open(path, &quot;a&quot;)\u003C\u002Fcode> adds at the end and creates the file when it is missing. \u003Ccode>open(path, &quot;w&quot;)\u003C\u002Fcode> empties it first, then writes at the start.\u003C\u002Fp>\n\u003Cp>Change the \u003Ccode>&quot;a&quot;\u003C\u002Fcode> in your copy to \u003Ccode>&quot;w&quot;\u003C\u002Fcode> and run the checker again. You get \u003Ccode>4 of 7 checks passed\u003C\u002Fcode>. The second run no longer shows the first note, and the counts for two and three lines fail. The count reads 1 on every run, because the file only ever holds the line you just wrote. Nothing raised an error, and the earlier notes were overwritten.\u003C\u002Fp>\n","\u003Cul>\n\u003Cli>\u003Ccode>read()\u003C\u002Fcode> moves the file pointer to the end, so a second \u003Ccode>read()\u003C\u002Fcode> on the same handle returns \u003Ccode>&#39;&#39;\u003C\u002Fcode> and every count built on it is zero.\u003C\u002Fli>\n\u003Cli>The file on disk is fine: \u003Ccode>tell()\u003C\u002Fcode> reports 5 after reading a 5-byte file, which is where the next read starts.\u003C\u002Fli>\n\u003Cli>Read once into a variable and count that, or call \u003Ccode>seek(0)\u003C\u002Fcode> to send the pointer back to the start.\u003C\u002Fli>\n\u003Cli>\u003Ccode>open(path, &quot;a&quot;)\u003C\u002Fcode> appends and creates the file when it is missing, while \u003Ccode>&quot;w&quot;\u003C\u002Fcode> empties it before writing, so the mode determines whether yesterday&#39;s notes survive.\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,[86,87,108],"\u002Fog\u002Fpython-capstone-gradebook.png",{"id":218,"title":55,"title_id":56,"slug":57},[271],{"authors_id":272},{"id":114,"name":115,"slug":116,"role":117,"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":105,"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":114,"name":115,"slug":116,"role":117,"profile_picture":21},{"id":295,"title":296,"title_id":297,"slug":298,"excerpt":299,"excerpt_id":300,"has_translation":12,"published_at":83,"reading_time":84,"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":114,"name":115,"slug":116,"role":117,"profile_picture":21},{"id":77,"title":78,"title_id":79,"slug":80,"excerpt":81,"excerpt_id":82,"has_translation":12,"published_at":83,"reading_time":84,"hidden_from_listing":15,"tags":85,"thumbnail_image":21,"og_image":88,"series":313,"authors":314},{"id":90,"title":91,"title_id":92,"slug":93},[315],{"authors_id":316},{"id":114,"name":115,"slug":116,"role":117,"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":141,"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,127],"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":114,"name":115,"slug":116,"role":117,"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":141,"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,189],"\u002Fog\u002Fpascal-debugging-fpc-gdb.png",{"id":308,"title":67,"title_id":68,"slug":69},[348],{"authors_id":349},{"id":114,"name":115,"slug":116,"role":117,"profile_picture":21},[351,355,358,361,364],{"text":352,"depth":353,"id":354},"The count that says zero",2,"the-count-that-says-zero",{"text":356,"depth":353,"id":357},"The file was fine; the pointer was not","the-file-was-fine-the-pointer-was-not",{"text":359,"depth":353,"id":360},"The checker","the-checker",{"text":362,"depth":353,"id":363},"Read once, then count","read-once-then-count",{"text":365,"depth":353,"id":366},"Append is not overwrite","append-is-not-overwrite",1795825297461]