How to redirect the output of a python script from standout(ie., A monitor) on to a file?



How to redirect the output of a python script from standout(ie., A monitor) on to a file?..

Answer / Komal

To redirect the standard output (stdout) of a Python script to a file, you can use the built-in `sys` module and `open()` function. Here's an example:nn``pythonnimport sysnsys.stdout = open('output.txt', 'w')nprint('Hello, World!')nsys.stdout.close()n`` This code will write the output of your script to a file named 'output.txt'.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

How can I make a time delay in python?

1 Answers  


What is the output of this code?

1 Answers  


How would you achieve web scraping in python?

1 Answers  


Can you explain the life cycle of a thread?

1 Answers  


What is the use of sessions in Django?

2 Answers  


Which is the package fastest form of python?

1 Answers  


What is orm in python?

1 Answers  


How many types of operators python has?

1 Answers  


Mention what is flask-wtf and what are their features?

1 Answers  


Which gui is best for python?

1 Answers  


What is the best free ide for python?

1 Answers  


What are the key features of using python?

1 Answers  


Categories