I want to write to a file in tabular format and following is code I have written till now.
file_out=open("testing_string","w")
file_out.write("{0:<12} {1:<20} {2:<30}\n".format("TUPLE","LOGFILE STATUS","FSDB STATUS"))
file_out.write("{0:12}".format("Check"))
file_out.write("{0:12}".format("_5"))
file_out.close()
Testing_string looks like this.
TUPLE LOGFILE STATUS FSDB STATUS
Check _5
Problem is I want _5 to be with check. Please see that I cannot concatenate check with _5 as check is printed first in file then depeding on some logic I fill LOGFILE STATUS FSDB STATUS. If I am unable to fill status then I check if I have to append _5 or not. so due to this I cannot concatenate string. How to then print _5 right next to Check?
'Check 'and then backspace to write out_5.'\b'character, which is the ASCII character code 8, literally called "backspace". It's not elegant, but it's possible.Check \b\b\b_5which may more or may not work. Displaying that file may show the right thing but the file still contains the extra characters, e.g. if you were to read it back in with python, you would have to explicitly deal with\b\b\b.