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

3
  • So where are the "various things" you've tried? Commented May 8, 2014 at 13:31
  • I was wondering if someone could use this particular example as other examples are clearly not easily transferable Commented May 8, 2014 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? Commented May 8, 2014 at 14:12

1 Answer 1

2

How about this?

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

Like mentioned in: Replace console output in Python

Sign up to request clarification or add additional context in comments.

4 Comments

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"
It actually can take 2 arguments like: sys.stdout.write("\rSearching Files: %s" % searchedfile)
Perfect! Exactly the help I was after.
@Christiaan: actually, that's just one argument: "\rSearching Files: %s" % searchedfile evaluates to a single string which is passed to sys.stdout.write()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.