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