Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 22nd, 2004, 11:43 PM
7imz 7imz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 10 7imz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old March 23rd, 2004, 01:44 AM
Boceifus's Avatar
Boceifus Boceifus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 95 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 2 m 36 sec
Reputation Power: 5
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?!?!?

Reply With Quote
  #3  
Old March 23rd, 2004, 10:01 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 10 m 32 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #4  
Old March 23rd, 2004, 11:54 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
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 ***

Reply With Quote
  #5  
Old March 24th, 2004, 12:09 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,243 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 5 h 41 m 59 sec
Reputation Power: 265
Quote:
Originally Posted by 7imz
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


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

Reply With Quote
  #6  
Old April 23rd, 2004, 11:51 AM
luckyboy luckyboy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 57 luckyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 58 sec
Reputation Power: 5
Hi

I think this is what you rae trying

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

print ans

Reply With Quote
  #7  
Old October 13th, 2004, 12:41 PM
Father Ted Father Ted is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 Father Ted User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > python p.py < t.txt (reading from standard input)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT