Not logged in
Login
Signup
Activity Log
Challenges
Forums
Help
You are here:
Home
→
Forums
→
Python
→
Input Methods
Input Methods
Add a reply
Posted by
CodePenguin
833 days ago:
What are the best ways to gather input in python? I have used the raw_input() - When you only need to get one line of input (ie: Home on the Range)
But what is the best way to get a undetermined amount of input? I'm trying to find solutions that do not require the importing of the sys module.
Quote this
Posted by
jackdied
749 days ago:
os.read(0,somebignumber) # not usually useful
input() # in place of int(raw_input())
sys.stdin
Quote this
Posted by
Mark Byers
746 days ago:
The only way I can think of to read an unknown number of lines of input *without* importing sys is to use a try/except block:
x=''
try:
while 1:x+=raw_input()
except:0
However, it's shorter to import sys:
import sys
x=sys.stdin.read()
Quote this
Posted by
toxik
473 days ago:
Take into consideration that some of these variants are easier to bake into existing loops, most notably the try...except one.
Quote this
Add a reply
A
29degrees
diversion |
But what is the best way to get a undetermined amount of input? I'm trying to find solutions that do not require the importing of the sys module.