Home python строка не найдена

строка не найдена




I don’t even know how to formulate a question that he would be clear, but still I will try. As a result, I want to make my mini-chat – I can receive new messages while entering your message text.

I need a way to make simultaneous input and conclusion in the console. I tried to do this: With the help of ESC sequences, move the string with the input, then move above, display the text to the libeled string, and then return back to the string down, where the text Introduced by me and input invitation. It turned out to be very ineffective and inconvenient code, as the invitation and text disappeared when I try to insert a string when the console window was already approached. There were also problems that if several rows are displayed on the screen, it all moved only to one line, and I wrote the input along the led text. I have yet been using the solution to receive data only at the end of input, but I would like that I could receive the necessary information directly during input.

Perhaps as suggested @Andreymal, it is worth making 2 sections – downstairs input, from above, but I can’t imagine how I heard that there are Curses, but only on Linux. Are there any other options with ready-made solutions, or should you continue to look for a solution with ESC sequences?

Answer 1

What do you mean under the Python Console? If the running script is running on the Windows command line, then you can so, with a carriage and self-written input. It is quite simple and works. The principle will be clear from this code.

import msvcrt
Import Time.
DEF input_wait (Prompt = '', timeout = 1000, *, _delay = 0.02):
  Inpute_Line = STR ()
  Start = Time.time ()
  While time.time () - Start & LT; Timeout:
    Prompt_t = '\ R {:. 1f} | {} {} '. Format (Timeout - time.time () + Start,
                      Prompt, Inpute_Line)
    Print (Prompt_t, End = '')
    If msvcrt.kbhit ():
      char = msvcrt.getwch ()
      if char == '\ r':
        MSVCRT.PutWCH ('\ n')
      Elif Char == '\ 000' or char == '\ xe0':
        MSVCRT.GetWCH ()
      ELIF ORD (CHAR) == 8: # Backspace
        Print ('\ R {}'. Format ('' * Len (Prompt_t)), End = '')
        Inpute_Line = Inpute_Line [: - 1]
        Inpute_Line + = Char
      Time.Sleep (_delay)
    Inpute_Line = None
  Return Inpute_Line
Timeout = 10.
Prompt = 'ENVER ANSWER:'
Print (how much will 5 + 5? ')
Print ('you have 10 seconds')
While True:
  Answer = Input_Wait (Prompt, TimeOut = Timeout)
  IF Answer Is None:
    Print ('\ Ntime Is Up')
    IF Answer == '10':
      Print ("IT's Right Answer!")
    ELIF ANSWER == 'Q':
      Print ('exit ...')
      Print ("No! Try Again.")

As far as I understand, you need to redraw not one line, but a few. Here is a code that demonstrates the free movement of the cursor for the carriage perverted.

from __future__ import print_function
Import colorama.
From Time Import Sleep
colorama.init ()
# # ESC [N A # Move Cursor N Lines Up
# # ESC [N B # Move Cursor N Lines Down
Cursor_Up = Lambda Lines: '\ x1b [{0} a'.Format (Lines)
cursor_down = lambda lines: '\ x1b [{0} b'.Format (Lines)
Print ("MEOW :)")
Print ("MEOW-MEOW :)")
Print ("MEOW-MEOW-MEOW :)")
Lines_Up = 3.
Print (Cursor_up (Lines_UP), END = '')
Sleep (1)
Print ("Woof", "" * 10)
Sleep (1)
Lines_Down = 1.
Sleep (1)
Print (Cursor_Down (Lines_Down), END = '')
Sleep (1)
Print ("Woof Woof Woof", "" * 10)
Sleep (1)
Lines_Up = 2.
Sleep (1)
Print (Cursor_up (Lines_UP), END = '')
Print ("Woof Woof", "" * 10)
Sleep (1)

With this understanding, you can freely output in the command line any information on the set of strings, constantly update it and simultaneously write to your input.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions