<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>File Read/Write on Semonan Book</title><link>https://semonan.com/en/tags/file-read/write/</link><description>Recent content in File Read/Write on Semonan Book</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 26 Aug 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://semonan.com/en/tags/file-read/write/rss.xml" rel="self" type="application/rss+xml"/><item><title>Read/Write a file</title><link>https://semonan.com/en/book/programming/python/file-io/</link><pubDate>Mon, 26 Aug 2024 00:00:00 +0000</pubDate><guid>https://semonan.com/en/book/programming/python/file-io/</guid><description>&lt;h1 id="how-to-read-and-write-files-in-python"&gt;How to Read and Write Files in Python&lt;a class="anchor" href="#how-to-read-and-write-files-in-python"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide explains how to read and write files in Python.&lt;br&gt;
It is organized around the most commonly used example codes.&lt;/p&gt;
&lt;h2 id="1-reading-a-text-file---reading-the-entire-file"&gt;1. Reading a Text File - Reading the Entire File&lt;a class="anchor" href="#1-reading-a-text-file---reading-the-entire-file"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You can create a file stream using &lt;code&gt;open(&amp;quot;abcd.txt&amp;quot;, &amp;quot;r&amp;quot;)&lt;/code&gt; and read the entire file at once with &lt;code&gt;.read()&lt;/code&gt;.&lt;br&gt;
(Creating a file stream means establishing a link to access the file.)&lt;br&gt;
Here, &lt;code&gt;&amp;quot;abcd.txt&amp;quot;&lt;/code&gt; refers to the full path of the file to be read, and you can use either an absolute path or a relative path.&lt;br&gt;
&lt;code&gt;&amp;quot;r&amp;quot;&lt;/code&gt; stands for read mode.&lt;/p&gt;</description></item></channel></rss>