-1

I want to write a code to read a input from user that include newline(enter key) Something like :

begin west  north
north  east east south 
east end

and when I press enter , do something for example :

line = 0
if input=='\n':
     line += 1

How can I do it!?

ariankazemi
  • 105
  • 3
  • 14
  • 2
    Does this answer your question? [How to read multiple lines of raw input?](https://stackoverflow.com/questions/11664443/how-to-read-multiple-lines-of-raw-input) – Grismar Dec 18 '21 at 04:47

3 Answers3

0

I don't think folks really grasp what he was after. Most of the time, he wants to input and act on a single line. But if he types "begin", then he wants to accumulate until the user enters a blank line. This does that:

def getinput():
    start = input(">> ")
    if 'begin' in start:
        while 1:
            line = input("+> ")
            if not line:
                break
            start += line
    return start

print(getinput())
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
  • If folks don't grasp what he's after, then the question is unclear and should be closed as such. And his example input ends with "end", so might want to stop reading, if the line ends with it. He might also not want "begin" and "end" in the read input. But those are all just guesses. – gre_gor Dec 18 '21 at 19:15
  • And your code would start reading multiple lines with the string "This is the beginning", which I doubt is desirable. Your code also doesn't include newlines. – gre_gor Dec 18 '21 at 19:18
  • Given his sample text, I'm guessing he's creating an adventure game and wants to stack up multiple commands. Given that, neither of your concerns will be an issue. – Tim Roberts Dec 19 '21 at 00:42
-1

obviously no one here knows exactly its purpose, but how can you do this with the help of a loop?

while 1:
if input():
    print("\n")
    

As long as there is an input, the value of the input will be equal to == enter, as I said, nobody knows what to do, but this is it.

With the help of the module

import pyautogui
 
pyautogui.press('enter') 

Have a good day.

Schart
  • 56
  • 1
  • 3
  • What are you rambling about? And neither of those code snippets capture multiple lines. – gre_gor Dec 18 '21 at 05:12
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 18 '21 at 06:24
-1

Try this

'''python

Lines_string = [] #save all lines write for user

#add line in list (lines_string)
While true:
     Line = input() #get user writing 

     if Line == "[exit]": 
        Break #break loop 
     else:
        Lines_string.append(Line) # save line in the list 
        

#read list 
for line, data in enumerator(Lines_string):
      # save data in file text for example 

'''

in framework is for example

#pyside6 is
inputText.PressedReturn.connect(method)

Sorry for my english :'c

if you want only read line and print try this

while True: #infinite loop
     line = input() #read data user writeing
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 18 '21 at 06:28