Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Reading Files in Python

>>> f = open("test.txt",'r',encoding = 'utf-8')
>>> f.read(4)    # read the first 4 data
'This'

>>> f.read(4)    # read the next 4 data
' is '

>>> f.read()     # read in the rest till end of file
'my first file
This file
contains three lines
'

>>> f.read()  # further reading returns empty sting
''
Source by www.guru99.com #
 
PREVIOUS NEXT
Tagged: #Reading #Files #Python
ADD COMMENT
Topic
Name
8+6 =