March 22nd, 2004, 11:43 PM
python p.py < t.txt (reading from standard input)
how can i do this operation...
but it's not accomplishing anything...
how i can i just read the data and right it on the screen
March 23rd, 2004, 01:44 AM
you do something like this
file = open('path\to\file', 'r') # r=read,w=write,a=append,etc
print file.readlines() #or you could use file.read()
#or you could read it line by line
print file.readline() #prints first line
print file.readline() #prints second line
It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?
March 23rd, 2004, 10:01 AM
Not 100% on what your trying to do 7. If your talking about getting user input and outputting to the console window then you looking for the raw_input() function. If not then what are you trying to do with sys.stdin?
March 23rd, 2004, 11:54 AM
python prog.py < mytext.txt
This will read the redirected file:
text = sys.stdin.read()
#Basic printing to stdout
#or useing the file methods
March 24th, 2004, 12:09 PM
Your code works fine for me:
Originally Posted by 7imz
Of course if you are taking the input from the keyboard instead of a file or pipe it will keep reading until you enter an EOF character (ctrl-Z on Windows), then it will echo it all in one go. If you want it to echo a line at a time then put it in a loop and use stdin.readline()
E:\prj\sandbox>python test.py <test.py
Dave - The Developers' Coach
April 23rd, 2004, 11:51 AM
I think this is what you rae trying
ans=raw_input(" Enter your name : ")
October 13th, 2004, 12:41 PM
print "Enter username:"
user = sys.stdin.readline().strip()
Sorry, we don't allow self promotion until 100 posts and 90 day period.[/edit]
Last edited by Scorpions4ever; October 13th, 2004 at 12:45 PM.