1

If I have an easy code like this:

while 1:
    text = raw_input()
    print 'You have written "%s" text'% (text)

if I start the program and I write "hello" the Output is:

hello
You have written "hello" text

The first "hello" is my input (taken with raw_input but I could use sys.stdin.readline too)

How I can delete the first "hello" (my input) to have an output only like this:

You have written "hello" text
5
  • 1
    import curses; curses.noecho() (unix-based only) Commented Nov 22, 2015 at 11:02
  • that's not something you want to do usually; the user normally wants to see what he/she's entering. except for passwords. you could have a look at getpass. Commented Nov 22, 2015 at 11:02
  • can i do without importing curses? Commented Nov 22, 2015 at 11:03
  • i need this for a chatting client Commented Nov 22, 2015 at 11:08
  • 1
    maybe: docs.python.org/2/library/getpass.html#getpass.getpass Commented Nov 22, 2015 at 11:31

1 Answer 1

1

You could clear the CLI before printing your wanted line.

import os
os.system('clear')

If it's a Unix system. On Windows it's cls.

Edit: If you need this for a chat client you could save your user inputs in a list and clear the cli and print your user inputs list

userInputs = []
...
text = raw_input ()
userInputs.append (text)   
os.system ('clear')
for i in userInputs:
    print (i)
Sign up to request clarification or add additional context in comments.

6 Comments

Also: os.system('cls' if os.name == 'nt' else 'clear')
Thanks, but with this code i delete all the text in the console and i don't want , i only want to delete user input
Hm... there is no simple way to prevent input is printed. You could cache the wanted output, clear the cli and print your cached output again with your new line and so on.
I need this becouse when I write on my client ( pastebin.com/JB36Emx6 )and I enter the input and then recive the same input from the server but with the time ,the address ,and other information, I prefer to recive only from the server and not see my input in the console ... sorry for my english
I have edited my post
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.