Answers for "read data file in python"

73

python write to file

file = open(“testfile.txt”,”w”) 
 
file.write(“Hello World”) 
file.write(“This is our new text file”) 
file.write(“and this is another line.”) 
file.write(“Why? Because we can.”) 
 
file.close() 
Posted by: Guest on December-09-2019
3

python open and read file with

with open('pagehead.section.htm','r') as f:
    output = f.read()
Posted by: Guest on May-15-2020
0

how to read a file in python

# 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.
Posted by: Guest on August-29-2021
-1

how to read a file in python

# when you want to read the file from terminal in python use 
import sys
f = open(sys.argv[1])
line=f.readline()
Posted by: Guest on March-05-2021

Python Answers by Framework

Browse Popular Code Answers by Language