print a file python code example
Example 1: python file reading
fin = open("NAME.txt", 'r')
body = fin.read().split("\n")
line = fin.readline().strip()
Example 2: python print file
import sys
# only this print call will write in the file
print("Hello Python!", file=open('output.txt','a'))
# not this one (std output)
print("Not written")
# any further print will be done in the file
sys.stdout = open('output.txt','wt')
print("Hello Python!")