Python Forum

Full Version: how do i make text apear only once
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i am trying to make a simple program with numbers, but whenever i attempt to add a number, i know i have to make ONE new line, but is it possible to make it so that the value of the number variable can only appear onscreen once
that is what i need.
thanks!

also! i need only one text to disapear. for example, if i printed it as 32, i would need 32 to be blocked, but then if i changed it to 47 then i would need 32 to be blocked but not 47. once i print 47, then i have to block IT to.

Thanks!
-ScMc
(Jul-24-2018, 02:31 PM)ScMc1943 Wrote: [ -> ]i would need 32 to be blocked
What does "blocked" mean?

And yes, it's very easy to only print a number once: call print() one time.
It is cryptic for me what you want to accomplish.

However, if you want have output of numbers on same row then it can be done with something like below. There will be numbers from 1 to 10 with 0.2 second interval 'overwritten' on same row and last number i.e. 10 will stay on screen:

import time

for i in range(1, 11):
    print(f'{i}', end='')
    if i == 10:
        break
    time.sleep(0.2)
    print('\r', end='')
ok so basically, here is what i meant. when i said blocked, i meant not able to be printed again even if the print method is called, as my problem, is that the print method is being called to much, because i have to put
     fileinteger = ""
    for char in file:
        fileinteger += char
         if fileinteger == "\n":
                print(" - " + string + " - ")
                i += 1
i and string where already defined earlier in the text.
the problem is, that i need to make it so that STRING can only be printed once, BUT if the value of STRING changes, then i need the original value to still only print once, but this new value to be able to print until printed, if main.txt, has more than one space.
MAIN.TXT:
hello
welcome to the program!
-just pretend this spot is a space ok?
the problem is that hello shows twice. i need it to show ONCE
?

class UniquePrint:
    def __init__(self, print=print):
        self.output = print
        self.previously_seen = []

    def print(self, message=""):
        if message not in self.previously_seen:
            self.previously_seen.append(message)
            self.output(message)

printer = UniquePrint()
with open("some_file.txt") as f:
    for line in f:
        # will not print duplicate lines
        printer.print(line)
thanks it worked!

Smile