Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python print on file

import sys

print('This message will be displayed on the screen.')

original_stdout = sys.stdout # Save a reference to the original standard output

with open('filename.txt', 'w') as f:
    sys.stdout = f # Change the standard output to the file we created.
    print('This message will be written to a file.')
    sys.stdout = original_stdout # Reset the standard output to its original value
Comment

PREVIOUS NEXT
Code Example
Python :: python get desktop directory 
Python :: Plot regression line from sklearn 
Python :: panda3d 
Python :: python3 strip punctuation from string 
Python :: create and use python classes 
Python :: pyhton mahalanobis distance 
Python :: print map object python 
Python :: pandas backfill 
Python :: how to delete a column from a dataframe in python 
Python :: excel get unique values from column formula 
Python :: How to use threading in pyqt5 
Python :: pandas dataframe read string as date 
Python :: solve sympy 
Python :: how to save the model in python 
Python :: np argmin top n 
Python :: seaborn bar plot 
Python :: loop through a column in pandas 
Python :: custom save django 
Python :: python group by multiple aggregates 
Python :: python replace character in string 
Python :: how to get unique value of all columns in pandas 
Python :: dataframe delete duplicate rows with same column value 
Python :: get prime number python 
Python :: streamlit python install 
Python :: convert dictionary keys/values to lowercase in python 
Python :: python nested list comprehension 
Python :: python get last element of list 
Python :: python operators 
Python :: python f string 
Python :: pandas max columns 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =