1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2004
Posts
10
Rep Power
0

python p.py < t.txt (reading from standard input)

how can i do this operation...

i've tried

import sys

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

#or you could read it line by line
etc
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
#Basic printing to stdout
print text
#or useing the file methods
sys.stdout.write(text)
Grim
5. No Profile Picture
Contributing User
Devshed Intermediate (1500 - 1999 posts)

Join Date
Feb 2004
Location
London, England
Posts
1,585
Rep Power
1374
Originally Posted by 7imz
how can i do this operation...

i've tried

import sys

but it's not accomplishing anything...

how i can i just read the data and right it on the screen
Your code works fine for me:

Code:
E:\prj\sandbox>python test.py <test.py
import sys

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. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2004
Posts
57
Rep Power
12
Hi

I think this is what you rae trying

import sys
ans=raw_input(" Enter your name : ")

print ans
7. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Oct 2004
Posts
2
Rep Power
0
import sys