Home:ALL Converter>How to write a output of a Python in a text file?

How to write a output of a Python in a text file?

Ask Time:2022-07-28T01:31:04         Author:K.Tom

Json Formatter

How to write a output of Python in a text file in Python? Below is the code and tried Open file function and it is not working

Code:
====
import os
# folder path
file_path = "/emp_Files/"
# list to store files
res = []
# Iterate directory
for file in os.listdir(file_path):
    if file.endswith('.csv'):
        res.append(file)
print(res)
f=open("/emp_Files/output.txt","w")
for res in result:
    print >> f, res
f.close()


Output:
=======
info_0_1_0.csv
info_0_2_0.csv
info_0_3_0.csv


Required output in txt file:
===========================
info_0_1_0.csv
info_0_2_0.csv
info_0_3_0.csv

Author:K.Tom,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73142293/how-to-write-a-output-of-a-python-in-a-text-file
yy