0

I have searched trough many answers on this site but none are working for me. I want to overwrite the print within this loop every time it loops:

for searchedfile in searchedfiles:
    print ("Searching Files:", searchedfile)
    with open(searchedfile) as f_in, open(outfilecamera, 'a') as f_out:
        f_out.writelines(searchedfile)
        f_out.writelines(ii)
        matched_lines = list(line for line in f_in if "timeout of" in line)          
        f_out.writelines(matched_lines)
        for line in searchedfile.split("\n"):
             if "Cycle " in line:
                 cycleno = line.split("#")[-1].split(".log")[0]
        file_counts.append((cycleno,len(matched_lines)))

I have tried various things including "\r" but i cannot seem to get it right.

Thanks

Jason Rogers
  • 667
  • 1
  • 6
  • 19
  • So where are the "various things" you've tried? – jonrsharpe May 08 '14 at 13:31
  • I was wondering if someone could use this particular example as other examples are clearly not easily transferable – Jason Rogers May 08 '14 at 13:48
  • What? You say you have searched through many answers but none are working for you; how are we supposed to suggest alternatives if we don't know what you've already tried? – jonrsharpe May 08 '14 at 14:12

1 Answers1

2

How about this?

sys.stdout.write("\rDoing thing %i" % i)
sys.stdout.flush()

Like mentioned in: Replace console output in Python

Community
  • 1
  • 1
Christiaan
  • 183
  • 1
  • 12
  • sys.stdout.write as far as I know takes 1 argument and I have 2 "("Searching Files:", searchedfile)". I did read that post as I said in the question: "I have searched trough many answers on this site" – Jason Rogers May 08 '14 at 13:45
  • 1
    It actually can take 2 arguments like: sys.stdout.write("\rSearching Files: %s" % searchedfile) – Christiaan May 08 '14 at 13:49
  • 1
    Perfect! Exactly the help I was after. – Jason Rogers May 08 '14 at 13:52
  • 2
    @Christiaan: actually, that's just one argument: `"\rSearching Files: %s" % searchedfile` evaluates to a single string which is passed to `sys.stdout.write()` – Hugh Bothwell May 08 '14 at 15:33