Answers for "read file in pytho"

13

python read file to variable

with open('data.txt', 'r') as file:
    data = file.read().replace('\n', '')
Posted by: Guest on February-27-2020
41

python read file

with open("file.txt", "r") as txt_file:
  return txt_file.readlines()
Posted by: Guest on November-30-2020
0

how to read files in python

#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\n%s"%(text, line)
  
print(text)
Posted by: Guest on January-30-2021

Python Answers by Framework

Browse Popular Code Answers by Language