Ask a Question

A Log That Readable and is Pleasant to Read

SOLVED
MarkSchofer
Frequent Contributor

A Log That Readable and is Pleasant to Read

I write to one file when an error happens another when it works as expected.  
1. How do I programmatically purge the data.   or

Or can I read a nextvalue from a sequence or Insert a date time stamp so it is unique.

******oFile.Write(aqDateTime.Now())*****
2. How do I add a carriage return so the file is not all one line.

I am using Python

if DateCheck == 'Y':
#aqFile.WriteToTextFile("C:\Users\Schofem\CheckChecks.txt", "One", aqFile.ctANSI)
oFile = aqFile.OpenTextFile("C:\\Users\\Schofem\\Logs\\CheckChecks.txt", aqFile.faWrite, aqFile.ctANSI, False)
oFile.Write(DDT.CurrentDriver.Value[0])
oFile.Write(" - ")
oFile.Write(DDT.CurrentDriver.Value[26])
oFile.Write(" - ")
oFile.Write(DDT.CurrentDriver.Value[27])
oFile.Write(" - ")
oFile.Write("PassedDateCheck")
oFile.Write("The Test")
oFile.Close()
# else:
#aqFile.WriteToTextFile("C:\Users\Schofem\CheckChecks.txt", "One", aqFile.ctANSI)
# oFile = aqFile.OpenTextFile("C:\\Users\\Schofem\\BadChecks.txt", aqFile.faWrite, aqFile.ctANSI, False)
# oFile.Write(DDT.CurrentDriver.Value[0])
# oFile.Write(" - ")
# oFile.Write(DDT.CurrentDriver.Value[26])
# oFile.Write(" - ")
# oFile.Write(DDT.CurrentDriver.Value[27])
# oFile.Write(" - ")
# oFile.Write("FailedDateCheck")
# oFile.Write("The Test")
# oFile.Close()

 

5 REPLIES 5
Marsha_R
Champion Level 3

For #1, you already know how to get Today.  To write it here I think you will need to convert it to a string

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/datetimetoformat...

 

For #2, you can use WriteLine instead of Write

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/opentextfile.html

 

MarkSchofer
Frequent Contributor

Marsha Thank You Very much. It is still reading on one line.   However much improved. Thanks

# fOR AWHILE THIUS WAS THE NEW AND IMPROVED METHOD
# For #2, you can use WriteLine instead of Write -MARSHA
# #aqFile.WriteToTextFile("C:\Users\Schofem\CheckChecks.txt", "One", aqFile.ctANSI)
# oFile = aqFile.OpenTextFile("C:\\Users\\Schofem\\Logs\\CheckChecks.txt", aqFile.faWrite, aqFile.ctANSI, False)
# oFile.Write(DDT.CurrentDriver.Value[0])
# oFile.Write(" - ")
# oFile.Write(aqDateTime.Now())
# oFile.Write(DDT.CurrentDriver.Value[26])
# oFile.Write(" - ")
# oFile.Write(DDT.CurrentDriver.Value[27])
# oFile.Write(" - ")
# oFile.Write("PassedDateCheck")
# oFile.Write("The Test")
# oFile.Close()
sPath = "C:\\Users\\Schofem\\CheckChecks.txt" ******Note to those those scoring at home. Need the double forward slashes 
# Creates a text file at the specified location
aqFile.Create(sPath)
# Opens the created file for writing
myFile = aqFile.OpenTextFile(sPath, aqFile.faWrite, aqFile.ctUnicode)
# Writes text to the file
myFile.WriteLine(aqDateTime.Now())
myFile.WriteLine(DDT.CurrentDriver.Value[0])
myFile.WriteLine(DDT.CurrentDriver.Value[26])
myFile.WriteLine(DDT.CurrentDriver.Value[27])
# Closes the file
myFile.Close()

Hm I would have thought that had a <CR> in it.  You could try writing out a <CR> or <CR><LF> after the line and see what it does.

sonya_m
SmartBear Alumni (Retired)

Thank you Marsha !

 

Did the situation improve @MarkSchofer ?


Sonya Mihaljova
Community and Education Specialist

MarkSchofer
Frequent Contributor

This was never a major issue, however   the log is fine. The only problem is that I am looping through and processing records and it is only writing the last file processed.   Stated another way,  it only writes and does not append

cancel
Showing results for 
Search instead for 
Did you mean: