# How to read, and print to the screen a file in python!
f = open('fileName', 'r')
print(f.read())
f.close()
# Where "fileName" is obviously the name of your file that you want to read.
#Read files with loop
#Replace (File path) with your text file's path
file = open("(File path)", "r")
text = ""
for line in file:
text = "%s
%s"%(text, line)
print(text)
fileName = "file_name.txt" #Here you need to write the file name as a string
openLike = "" #Here you need to write how do you want to open the file:
#"w": Write, "r": Read
openedFile = open("file_name.txt", openLike) #Here you open the file
fileText = openedFile.read() #This read all the file
openedFile.close() #Close the file
print(fileText) # Prints the file text
my_file = open("C:UsersPythonfile.txt", "r")
#Give the path accurately and use
text = my_file.read()
print(text)
#Output: The text in file.txt will be printed
l_a=[]
l_m=[]
l_w=[]
with open("spots.txt","r") as file:
line=file.readlines()
for i in range(0,len(line),1):
[a,m,w]=line[i].split()
l_a.append(float(a))
l_m.append(float(m))
l_w.append(float(w))
l_a=[]
l_m=[]
l_w=[]
with open("spots.txt","r") as file:
line=file.readlines()
for i in range(0,len(line),1):
[a,m,w]=line[i].split()
l_a.append(float(a))
l_m.append(float(m))
l_w.append(float(w))
l_a=[]
l_m=[]
l_w=[]
with open("spots.txt","r") as file:
line=file.readlines()
for i in range(0,len(line),1):
[a,m,w]=line[i].split()
l_a.append(float(a))
l_m.append(float(m))
l_w.append(float(w))
>>> 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
''
l_a=[]
l_m=[]
l_w=[]
with open("spots.txt","r") as file:
line=file.readlines()
for i in range(0,len(line),1):
[a,m,w]=line[i].split()
l_a.append(float(a))
l_m.append(float(m))
l_w.append(float(w))