I have a log file where i'm fetching only the desired output and into two different variables and when i run the code it prints currently but i need both the variable data written into another file called file1.
I have the raw code sample which i tried working with print but not getting the idea about writing it into a file.
with open("testfile","r") as fh:
for line in fh:
if "ping" in line:
if HOST != "NA" and Flag:
mydata1 = hostname
elif HOST != "NA" and Flag and HOST not in mydata1:
mydata2 = logname
mydata3 = open('file1', 'w')
mydata3.write(mydata1,mydata2)
mydata3.close()
#print(mydata1,mydata2)
lif HOST != "NA" and Flag and HOST not in mydata1:hostnameorlogname? Please make a reproducible example. Also, there is theloggingmodule designed for logging; is there a reason you're not using that?loggingmodule.