Skip to content

Commit

Permalink
Merge pull request #6 from Vardan2009/master
Browse files Browse the repository at this point in the history
Added security notice in file handling page
  • Loading branch information
github-actions[bot] committed Oct 27, 2024
1 parent a2cb44b commit 60740dc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 42 deletions.
66 changes: 45 additions & 21 deletions file-handling.html
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,15 @@
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>

<li class="md-nav__item">
<a href="#security-notice-executing-any-file-operations-will-prompt-the-user-for-confirmation-before-proceeding-for-example" class="md-nav__link">
<span class="md-ellipsis">
SECURITY NOTICE: Executing any file operations will prompt the user for confirmation before proceeding, for example:
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#file-modes" class="md-nav__link">
<span class="md-ellipsis">
Expand Down Expand Up @@ -878,6 +887,15 @@
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>

<li class="md-nav__item">
<a href="#security-notice-executing-any-file-operations-will-prompt-the-user-for-confirmation-before-proceeding-for-example" class="md-nav__link">
<span class="md-ellipsis">
SECURITY NOTICE: Executing any file operations will prompt the user for confirmation before proceeding, for example:
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#file-modes" class="md-nav__link">
<span class="md-ellipsis">
Expand Down Expand Up @@ -938,6 +956,12 @@ <h1 id="file-handling">File handling<a class="headerlink" href="#file-handling"
<p>File handling is an essential part of any programming language. Radon provides
a simple way to read and write files. In this section, we will learn how to
read and write files in Radon.</p>
<blockquote>
<h3 id="security-notice-executing-any-file-operations-will-prompt-the-user-for-confirmation-before-proceeding-for-example"><strong>SECURITY NOTICE:</strong> Executing any file operations will prompt the user for confirmation before proceeding, for example:<a class="headerlink" href="#security-notice-executing-any-file-operations-will-prompt-the-user-for-confirmation-before-proceeding-for-example" title="Permanent link">&para;</a></h3>
<div class="language-text highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a>[DISK_ACCESS] This program is attempting to access the disk. Continue execution?
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a>[Y/n] -&gt; _
</span></code></pre></div>
</blockquote>
<h2 id="file-modes">File modes<a class="headerlink" href="#file-modes" title="Permanent link">&para;</a></h2>
<p>When opening a file, we can specify the mode in which we want to open the file.</p>
<p>The modes are:</p>
Expand All @@ -961,44 +985,44 @@ <h2 id="reading-from-a-file">Reading from a file<a class="headerlink" href="#rea
<p>To manipulate files in Radon, we use built-in <code>File</code> class. We can create a new
instance of <code>File</code> class by passing the file path to the constructor. We can
then use the <code>read</code> method to read the contents of the file.</p>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1">1</a></span>
<span class="normal"><a href="#__codelineno-0-2">2</a></span>
<span class="normal"><a href="#__codelineno-0-3">3</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1"></a><span class="n">file</span> <span class="o">=</span> <span class="n">File</span><span class="p">(</span><span class="s2">&quot;file.txt&quot;</span><span class="p">)</span>
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2"></a><span class="n">content</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
</span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3"></a><span class="nb">print</span><span class="p">(</span><span class="n">content</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
<p>You can also read the file line by line using the <code>readline</code> method.</p>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-1-1">1</a></span>
<span class="normal"><a href="#__codelineno-1-2">2</a></span>
<span class="normal"><a href="#__codelineno-1-3">3</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1"></a><span class="n">file</span> <span class="o">=</span> <span class="n">File</span><span class="p">(</span><span class="s2">&quot;file.txt&quot;</span><span class="p">)</span>
</span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2"></a><span class="n">line</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
</span><span id="__span-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3"></a><span class="nb">print</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
</span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2"></a><span class="n">content</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
</span><span id="__span-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3"></a><span class="nb">print</span><span class="p">(</span><span class="n">content</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
<p>You can also read all the lines of the file using the <code>readlines</code> method.</p>
<p>You can also read the file line by line using the <code>readline</code> method.</p>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-2-1">1</a></span>
<span class="normal"><a href="#__codelineno-2-2">2</a></span>
<span class="normal"><a href="#__codelineno-2-3">3</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1"></a><span class="n">file</span> <span class="o">=</span> <span class="n">File</span><span class="p">(</span><span class="s2">&quot;file.txt&quot;</span><span class="p">)</span>
</span><span id="__span-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2"></a><span class="n">lines</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span>
</span><span id="__span-2-3"><a id="__codelineno-2-3" name="__codelineno-2-3"></a><span class="nb">print</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>
</span><span id="__span-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2"></a><span class="n">line</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
</span><span id="__span-2-3"><a id="__codelineno-2-3" name="__codelineno-2-3"></a><span class="nb">print</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
<p>You can also read all the lines of the file using the <code>readlines</code> method.</p>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-3-1">1</a></span>
<span class="normal"><a href="#__codelineno-3-2">2</a></span>
<span class="normal"><a href="#__codelineno-3-3">3</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1"></a><span class="n">file</span> <span class="o">=</span> <span class="n">File</span><span class="p">(</span><span class="s2">&quot;file.txt&quot;</span><span class="p">)</span>
</span><span id="__span-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2"></a><span class="n">lines</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span>
</span><span id="__span-3-3"><a id="__codelineno-3-3" name="__codelineno-3-3"></a><span class="nb">print</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
<h2 id="writing-to-a-file">Writing to a file<a class="headerlink" href="#writing-to-a-file" title="Permanent link">&para;</a></h2>
<p>To write to a file, we use the <code>write</code> method. We can pass the content to the
<code>write</code> method to write to the file.</p>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-3-1">1</a></span>
<span class="normal"><a href="#__codelineno-3-2">2</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1"></a><span class="n">file</span> <span class="o">=</span> <span class="n">File</span><span class="p">(</span><span class="s2">&quot;file.txt&quot;</span><span class="p">)</span>
</span><span id="__span-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2"></a><span class="n">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Hello, World!&quot;</span><span class="p">)</span>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-4-1">1</a></span>
<span class="normal"><a href="#__codelineno-4-2">2</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1"></a><span class="n">file</span> <span class="o">=</span> <span class="n">File</span><span class="p">(</span><span class="s2">&quot;file.txt&quot;</span><span class="p">)</span>
</span><span id="__span-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2"></a><span class="n">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Hello, World!&quot;</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
<h2 id="closing-a-file">Closing a file<a class="headerlink" href="#closing-a-file" title="Permanent link">&para;</a></h2>
<p>After reading or writing to a file, it is important to close the file. We can
use the <code>close</code> method to close the file.</p>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-4-1">1</a></span>
<span class="normal"><a href="#__codelineno-4-2">2</a></span>
<span class="normal"><a href="#__codelineno-4-3">3</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1"></a><span class="n">file</span> <span class="o">=</span> <span class="n">File</span><span class="p">(</span><span class="s2">&quot;file.txt&quot;</span><span class="p">)</span>
</span><span id="__span-4-2"><a id="__codelineno-4-2" name="__codelineno-4-2"></a><span class="c1"># code that reads or writes to the file</span>
</span><span id="__span-4-3"><a id="__codelineno-4-3" name="__codelineno-4-3"></a><span class="n">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-5-1">1</a></span>
<span class="normal"><a href="#__codelineno-5-2">2</a></span>
<span class="normal"><a href="#__codelineno-5-3">3</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1"></a><span class="n">file</span> <span class="o">=</span> <span class="n">File</span><span class="p">(</span><span class="s2">&quot;file.txt&quot;</span><span class="p">)</span>
</span><span id="__span-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2"></a><span class="c1"># code that reads or writes to the file</span>
</span><span id="__span-5-3"><a id="__codelineno-5-3" name="__codelineno-5-3"></a><span class="n">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</span></code></pre></div></td></tr></table></div>
<p>Check the file is closed or not using the <code>is_closed</code> method.</p>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-5-1">1</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1"></a><span class="n">file</span><span class="o">.</span><span class="n">is_closed</span><span class="p">()</span>
<div class="language-py highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">file-handling.rn</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-6-1">1</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1"></a><span class="n">file</span><span class="o">.</span><span class="n">is_closed</span><span class="p">()</span>
</span></code></pre></div></td></tr></table></div>
<p>That's it! You now know how to read and write files in Radon.</p>

Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,102 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://radon-project.github.io/index.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/arrays.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/built-in-functions.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/classes.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/contribution.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/control-flow.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/data-types.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/error-handling.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/file-handling.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/functions.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/input-output.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/installation.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/language-reference.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/loops.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/modules.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/quick-start.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/standard-library.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/strings.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/tools.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://radon-project.github.io/blog/hello-world.html</loc>
<lastmod>2024-06-02</lastmod>
<lastmod>2024-10-27</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>
Binary file modified sitemap.xml.gz
Binary file not shown.

0 comments on commit 60740dc

Please sign in to comment.