aaa.txt:
aszczx
d
as
w
ad
python script:
f = open('aaa.txt','r')
f.read()
f.close()
Console:
C:\Python27>test.py
C:\Python27>
Why is it not displaying the contents of the file?
Thanks,
You are not displaying the contents of the file, just reading it.
For instance you could do something like this:
with open('aaa.txt') as infp:
data = infp.read()
print data # display data read
Using with will also close the file for your automatically
read() while you used readlines() - the two are different. readlines() will return a list of strings, while read() will return a big string.