473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

(std)input

Dear All,

I am not a programmer, and I could not find out the solution of the following problem:
I would like to pipe a program output to my python script; after it receives the EOF, I would like to get input from the users.
I do not know the programmer expression of this process. Something like that: I would like to set the stdin back to the keyboard.

A stupid example:
--------------------------
$cat text_file | my.py
Reading text_file...
text_file was loaded
Enter your comment:
--------------------------

Thanks for your help,
Tamas

Jul 18 '05 #1
1 1364
You might think of this a different way.

python my.py text_file
Enter your comment:

Have the python program pick up the file from
the argument list and read its contents, then
use raw_input to prompt the user.

You can do this with something like:

import sys
try: input_file=sys.argv[1]
except:
print "No input file specified, aborting"
sys.exit(2)

fp=open(input_file, 'r')
print "Reading text_file..."
data=fp.read()
fp.close()
print "text_file was loaded"
comment=raw_input("Enter your comment")

HTH,
Larry Bates
Syscon, Inc.
"Hegedus, Tamas ." <He***********@mayo.edu> wrote in message
news:ma**************************************@pyth on.org...
Dear All,

I am not a programmer, and I could not find out the solution of the following problem: I would like to pipe a program output to my python script; after it receives the EOF, I would like to get input from the users. I do not know the programmer expression of this process. Something like that: I would like to set the stdin back to the keyboard.
A stupid example:
--------------------------
$cat text_file | my.py
Reading text_file...
text_file was loaded
Enter your comment:
--------------------------

Thanks for your help,
Tamas

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: William Payne | last post by:
Hello, when I was writing a user-driven test program for a data structure I wrote, I encountered an annoying problem. The test program is laid out as a menu with several numbered options. The user...
16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
5
by: Kavya | last post by:
I saw these two ways for validating input First Way -------------- #include <iostream> #include <limits> using namespace std; int main() {
7
by: Grey Alien | last post by:
Does *ANYONE* in here know how I may parse the various date/time 'elements' from a string?. The input string has the ff format: 'YYYY-MM-DD HH:MM:SS AM'
13
by: cront | last post by:
I have a problem to work on: we will ask user to input anything and we will put that back onto the standard output with all set of brackets removed. We will not remove any single bracket e.g. ...
2
by: gopala | last post by:
Hi, I am pretty new to python but i do have experience with c++. As a part of learning exercise i wrote a python script to insert beautifying comments(with name, problem...) to our lab program...
24
by: arnuld | last post by:
I have a function named getword that read every single input from std. input. WHAT I WANTED: I want it read the word if it has less than or equal to 30 characters. Anything else beyond that...
7
by: Lie Ryan | last post by:
>>I want to write something that handle every char immediately after its Don't you think that getting a one-character from console is something that many people do very often? Do you think that...
9
by: arnuld | last post by:
Earlier, I have posted a program like this, a month ago IIRC. I have created it again, without looking at the old program. Can I have your opinions on this: 1) I wanted my program to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.