this will solve your issue:
answer = raw_input("Vilken?")
if answer.lower().strip() == "1":
print("Okej! (1)")
elif answer.lower().strip() == "2":
print("Okej! (2)")
elif answer.lower().strip() == "3":
print("Okej! (3)")
change input to raw_input
Answer from Night King on Stack Overflowthis will solve your issue:
answer = raw_input("Vilken?")
if answer.lower().strip() == "1":
print("Okej! (1)")
elif answer.lower().strip() == "2":
print("Okej! (2)")
elif answer.lower().strip() == "3":
print("Okej! (3)")
change input to raw_input
Change the name of the variable `answer to answer I think that's your problem
How to read a line in the terminal with python - Stack Overflow
How to read a line from python currently in console? - Stack Overflow
python - User input and command line arguments - Stack Overflow
Reading a line from standard input in Python - Stack Overflow
If you mean to read from the user/a pipe, then simply use input.
However, from your comments it seems like you want to be able to read from what has already been printed.
To do this, you have a few options. If you don't actually want it to display on the terminal, and you only care about certain part of the output, then you can use contextlib.redirect_stdout and contextlib.redirect_stderr. You can combine this with io.StringIO to capture the output of your application to a string. This has been discussed in the question Capture stdout from a script in Python
However, if you want to have something which provides you both a means of printing to the terminal and giving you the lines, then you will need to implement your own type which inherits from io.TextIOBase or uses io.TextIOWrapper.
Do you mean something like this?
name = input("Enter a name: ")
print(name)
To read user input you can try the cmd module for easily creating a mini-command line interpreter (with help texts and autocompletion) and raw_input (input for Python 3+) for reading a line of text from the user.
text = raw_input("prompt") # Python 2
text = input("prompt") # Python 3
Command line inputs are in sys.argv. Try this in your script:
import sys
print (sys.argv)
There are two modules for parsing command line options: (deprecated since Python 2.7, use optparseargparse instead) and getopt. If you just want to input files to your script, behold the power of fileinput.
The Python library reference is your friend.
var = raw_input("Please enter something: ")
print "you entered", var
Or for Python 3:
var = input("Please enter something: ")
print("You entered: " + var)
raw_input() takes an optional prompt argument. It also strips the trailing newline character from the string it returns, and supports history features if the readline module is loaded.
readline() takes an optional size argument, does not strip the trailing newline character and does not support history whatsoever.
Since they don't do the same thing, they're not really interchangeable. I personally prefer using raw_input() to fetch user input, and readline() to read lines out of a file.
"However, from the point of view of many Python beginners and educators, the use of sys.stdin.readline() presents the following problems:
Compared to the name "raw_input", the name "sys.stdin.readline()" is clunky and inelegant.
The names "sys" and "stdin" have no meaning for most beginners, who are mainly interested in what the function does, and not where in the package structure it is located. The lack of meaning also makes it difficult to remember: is it "sys.stdin.readline()", or " stdin.sys.readline()"? To a programming novice, there is not any obvious reason to prefer one over the other. In contrast, functions simple and direct names like print, input, and raw_input, and open are easier to remember." from here: http://www.python.org/dev/peps/pep-3111/
Hi, I've just gotten pihole 5.2.4 running on my raspberry pi 0 w. (First raspberry pi project I've done, pretty happy!) But I'm not quite done yet, I have something in mind I'd like to do with it. I'd like to filter out the live output from the pihole -t command to only include datapoints that include a certain IP address, or DNS that's been blocked. Could this be done in python?