-2

I know that this question has been asked before but after a long search I've couldnt find any solution that helps me. currently, I'm trying to open a file given by a user, read the file content and print each line in the same line overwriting the line.

Expected result:

Trying: xxx --> replace the xxx and write trying: yyy in the same position.

when tyring to implement this option I could get it with numbers but not with strings. this is my code example:

wordlist = input("Enter wordlist path")
with open(wordlist, 'r', encoding='utf-8') as wl:
for line in wl:
    r = requests.get(url + '/' + line)
    sys.stdout.write('trying: %s' % line)
    sys.stdout.flush()
    time.sleep(0.3)
kAssofer
  • 1
  • 1
  • Have you try `print(line, end="\r")` , it should work for string. – adamkwm Sep 10 '21 at 10:26
  • yeah I tried it but no success, it prints new line every time – kAssofer Sep 10 '21 at 11:08
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 16 '21 at 08:43

1 Answers1

0

Here is a link from 2008 addressing the same issue:

How to modify a text file?

To sum up: you will have to create a new file, open the existing file and write the modifications to the new file. In place modifications are not possible.