10 examples of 'how to read input from stdin in python' in Python

Every line of 'how to read input from stdin in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
34def get_input():
35 ch = sys.stdin.read(1)
36 # 方向键的开头
37 if ch == DIRECTIION_PREFIX:
38 ch += sys.stdin.read(2)
39 return ch
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

14def read_in():
15 lines = sys.stdin.readline()
16 # Since our input would only be having one line, parse our JSON data from that
17 return lines
38def read_stdin():
39 if select.select([sys.stdin,], [], [], 1.0)[0]:
40 return sys.stdin.read()
41 return ''
154def read(self, *args, **kwargs):
155 with self.notify_input_requested():
156 return self.original_stdin.read(*args, **kwargs)
21def _read_stdin(self):
22 self._stdout.write(">>> Jeev Console Adapater, running jeev v%s\n" % self._jeev.version)
23 self._stdout.write(">>> Switch channel using \c channel_name\n")
24 self._stdout.write(">>> Switch user using \u user_name\n")
25 self._stdout.write(">>> Jeev will respond to the user name %s\n" % self._jeev.name)
26 self._stdout.flush()
27
28 while True:
29 self._stdout.write('[%s@%s] > ' % (self._user, self._channel))
30 self._stdout.flush()
31
32 line = self._stdin.readline()
33 if not line:
34 break
35
36 if line.startswith('\c'):
37 self._channel = line[2:].strip().lstrip('#')
38 self._stdout.write("Switched channel to #%s\n" % self._channel)
39 self._stdout.flush()
40
41 elif line.startswith('\u'):
42 self._user = line[2:].strip()
43 self._stdout.write("Switched user %s\n" % self._user)
44 self._stdout.flush()
45
46 else:
47 message = Message({}, self._channel, self._user, line.strip())
48 self._jeev._handle_message(message)
90@abc.abstractmethod
91def input(self, string):
92 pass
10def test_stdin_input(self):
11 pass
36def raw_input(self, prompt=None):
37 if prompt:
38 self.write(prompt)
39 return self.readfunc()
121def get_interactive_input(phrase, filename, default):
122 """Returns the path to the cityscapes folder."""
123 value = default
124 # Does a file already exist?
125 if os.path.exists(filename):
126 # Read the path
127 with open(filename, "r") as f:
128 value = f.read()
129
130 # Ask the user for the actual path
131 user_input = raw_input("%s [%s]: " % (phrase, value))
132
133 # Did the user enter something?
134 if user_input != "":
135 # Yes, update the file
136 with open(filename, "w") as f:
137 f.write(user_input)
138 value = user_input
139
140 return value
171def get_input(self, prompt):
172 if self.raw_input:
173 try:
174 line = raw_input(prompt)
175 except (EOFError, KeyboardInterrupt):
176 line = 'EOF'
177 else:
178 self.write(prompt)
179 self.flush()
180 line = self.stdin.readline()
181 if not len(line):
182 line = 'EOF'
183 else:
184 line = line[:-1]
185 return line

Related snippets