I have list of elements and I want to write below elements to file using print() function using python.
Python gui: version 3.3
Sample code:
D = {'b': 2, 'c': 3, 'a': 1}
flog_out = open("Logfile.txt","w+")
for key in sorted(D):
print(key , '=>', D[key],flog_out)
flog_out.close()
Output when I run in IDLE gui:
a => 1 <_io.TextIOWrapper name='Logfile.txt' mode='w+' encoding='cp1252'>
b => 2 <_io.TextIOWrapper name='Logfile.txt' mode='w+' encoding='cp1252'>
c => 3 <_io.TextIOWrapper name='Logfile.txt' mode='w+' encoding='cp1252'>
I don't see any line written in the output file. I tried using the flog_out.write(), it looks we can pass one argument in write() function. Can anybody look into my code and tell if I'm missing something.