Wednesday, August 12, 2015

reading and writing from standard input/output in python


Here I am sharing a couple of ways that I use to perform I/O in python.

import sys
import fileinput
# working read a line from stdin
#x=sys.stdin.readline()
#print x

#working read the input from stdin, terminated by Ctrl + D
#x=sys.stdin.read()
#print x

#raw_input take an input and move ahead
#x=raw_input()
#name=raw_input()
#print x, name

# fileinput take the input from the file from command line argument, if the argument is null
# it take input from stdin

#for line in fileinput.input():
#    print line

x=0
mylist=[None]*10
while x<10:
   mylist[x]=raw_input()
   x=x+1


for a in mylist:
   print a+"  "




No comments:

Post a Comment