0

I'm new in python and i don't know how I can use increment to print the items from text file line by line. I don't want to print them all at once

This is my code:

with open('Users.txt', 'r', encoding='utf-8') as file:
    Usernames = file.readlines()
print(Usernames = Usernames +1)
martineau
  • 119,623
  • 25
  • 170
  • 301
  • Does this answer your question? [How to read a large file - line by line?](https://stackoverflow.com/questions/8009882/how-to-read-a-large-file-line-by-line) – TomServo Jun 18 '20 at 00:38

2 Answers2

0
with open('Users.txt', 'r', encoding='utf-8') as file:
    for line in file:
        print(line, end='')

You need the end='' on the print because the lines will already have a newline character append to them.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • y i know this will print all the lines from text file all at once , but i want to increment by example if Username == 'Jax': pla pla pla Username +=1 i want like that but it doesn't work with me – user11278488 Jun 18 '20 at 13:01
0

Use a for loop to print line-by-line:

import time
with open('Users.txt', 'r', encoding='utf-8') as file:
    for line in file:
        print(line)
        time.sleep(1)

The above code will wait 1 second after printing each line.