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

From XPUB & Lens-Based wiki
No edit summary
 
(2 intermediate revisions by the same user not shown)
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 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)