User:Simon/Trim4/tools/Python read file: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "For Python to read a file: <code> with open('README.md', 'r') as txt: txt_content = txt.read() print(txt_content)</code>")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Reading files==
For Python to read a file:
For Python to read a file:


<code>
<pre>
with open('README.md', 'r') as txt:  
with open('README.md', 'r') as txt:
 
     txt_content = txt.read()  
     txt_content = txt.read()  
 
print(txt_content)</pre>
 
print(txt_content)</code>

Latest revision as of 14:41, 20 June 2020

Reading files

For Python to read a file:

with open('README.md', 'r') as txt:
    txt_content = txt.read() 
print(txt_content)