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

From XPUB & Lens-Based wiki
No edit summary
 
Line 1: Line 1:
=Reading files=
==Reading files==


For Python to read a file:
For Python to read a file:


<nowiki>
<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)</nowiki>

Latest revision as of 15: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)