python program to read files from code example
Example 1: python read file
with open("file.txt", "r") as txt_file:
return txt_file.readlines()
Example 2: read file python
document = 'document.txt'
file = open(document, 'r')
file.seek(0)
for i in file:
k = i.strip()
print k
file.close()
with open(document) as ur:
for i in ur:
k = i.strip()
print k
Example 3: how to read files in python
file = open("(File path)", "r")
text = ""
for line in file:
text = "%s\n%s"%(text, line)
print(text)
Example 4: how to read a file in python
import sys
f = open(sys.argv[1])
line=f.readline()