Python Forum
how do i make text apear only once
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do i make text apear only once
#1
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
Reply
#2
(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.
Reply
#3
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='')
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
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
Reply
#5
?

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)
Reply
#6
thanks it worked!

Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  make all text in Right to left alignment in tkinter widgets jalal0034 1 1,412 Sep-27-2022, 06:42 PM
Last Post: Larz60+
  how to make a hotkey for text adventure game myn2018 2 2,029 Jan-06-2021, 10:39 PM
Last Post: myn2018
  Trying to make column based file from text file scor1pion 7 3,574 Jul-16-2019, 02:43 PM
Last Post: scor1pion
  How to make a script to find a certain word in text files in a whole directory ? RandoomDude 2 5,993 Apr-27-2017, 10:27 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020