|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
python p.py < t.txt (reading from standard input)
how can i do this operation...
i've tried import sys sys.stdout.write(sys.stdin.read()) but it's not accomplishing anything... how i can i just read the data and right it on the screen |
|
#2
|
||||
|
||||
|
you do something like this
Code:
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
etc
__________________
It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!? |
|
#3
|
||||
|
||||
|
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?
Mark. |
|
#4
|
||||
|
||||
|
python prog.py < mytext.txt
This will read the redirected file: Code:
import sys text = sys.stdin.read() #Basic printing to stdout print text #or useing the file methods sys.stdout.write(text) Grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#5
|
|||
|
|||
|
Quote:
Your code works fine for me: Code:
E:\prj\sandbox>python test.py <test.py import sys sys.stdout.write(sys.stdin.read()) E:\prj\sandbox> 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() Dave - The Developers' Coach |
|
#6
|
|||
|
|||
|
Hi
I think this is what you rae trying import sys ans=raw_input(" Enter your name : ") print ans |
|
#7
|
|||
|
|||
|
import sys
print "Enter username:" user = sys.stdin.readline().strip() [edit]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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > python p.py < t.txt (reading from standard input) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|