Python Forum

Full Version: How to generate a log in a list style?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Guys, I have a code for bkp my network devices, I have placed some improvement to generate a log for document the failed devices, so I can check it manually.
My code is generating the output I want in a text, however I'd like to improve the formatting...

The code generates the log file in one single line and my goal is to generate a list instead.

my code is:
except Exception as ex:
            print('An exception occurred.  Details', ex)
            output2 = ip + ','
            print output2
            filename2 = "%s_%.2i-%.2i-%i_%.2i-%.2i-%.2i" % (filename_prefix2,,now.month,now.year,now.hour,now.minute,now.second)
            ff = open(filename2, 'a')
and I got the text file like this:

Id like to getsomething like that:

Insert some newlines in place of commas.


# Or

Replace +',' with +'\n'
also look at logging module
Thank you guys, the '\n' solved my problem.
(Apr-22-2020, 12:41 PM)wagnergt12 Wrote: [ -> ]Thank you guys, the '\n' solved my problem.
it solved your problem. However if you want to do logging properly, look at the logging module