Answers for "python code for printing files"

1

code for showing contents of a file and printing it in python

import os

with open("filename", "r+") as file:
    content = file.readline()
    while(content!=""):
      	print(content)
        content = file.readline()
    file.close
Posted by: Guest on August-05-2020
1

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!")
Posted by: Guest on April-19-2021

Code answers related to "python code for printing files"

Python Answers by Framework

Browse Popular Code Answers by Language