file input in python code example
Example 1: file input python
# import fileinput
import fileinput
# Using fileinput.input() method
for line in fileinput.input(files ='gfg.txt'):
print(line)
Example 2: read and write to file python
file = open(“testfile.txt”, “r+”)