473,405 Members | 2,444 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,405 software developers and data experts.

std in and stdout

hello,

i have a question!

how would i fix the following problem:

now i have an input file with a fix name and an output file!
i have this two files hardcoded written in the sourcecode of this function!

in the future i will start this script with the command line.
the syntax should be look like this:

Python Function | Source File | Output File
-------------------------------------------------------
fileanalyse.py sourcefile.csv filenalyse.txt

i will call the programm always with the commandline, that i could type in
various filenames for the input and output files!

could anybody help me?!

Jul 10 '06 #1
2 1247
Juergen Huber írta:
hello,

i have a question!

how would i fix the following problem:

now i have an input file with a fix name and an output file!
i have this two files hardcoded written in the sourcecode of this function!

in the future i will start this script with the command line.
the syntax should be look like this:

Python Function | Source File | Output File
-------------------------------------------------------
fileanalyse.py sourcefile.csv filenalyse.txt

i will call the programm always with the commandline, that i could type in
various filenames for the input and output files!

could anybody help me?!

You might want to use sys.argv or the much nicer optparse module:

http://docs.python.org/lib/module-optparse.html

I might not have understood your problem, though. :)

Laszlo

Jul 10 '06 #2
Juergen Huber wrote:
how would i fix the following problem:

now i have an input file with a fix name and an output file!
i have this two files hardcoded written in the sourcecode of this
function!

in the future i will start this script with the command line.
the syntax should be look like this:

Python Function | Source File | Output File
-------------------------------------------------------
fileanalyse.py sourcefile.csv filenalyse.txt

i will call the programm always with the commandline, that i could type in
various filenames for the input and output files!

could anybody help me?!
Are you perhaps looking for sys.argv? The following example takes filenames
from the command line and defaults to stdin/stdout:

import sys

def analyse(instream, outstream):
pass # your code

instream = sys.stdin
outstream = sys.stdout

if len(sys.argv) 1:
instream = open(sys.argv[1])
if len(sys.argv) 2:
outstream = open(sys.argv[2], "w")

analyse(instream, outstream)

instream.close()
outstream.close()

Peter

PS: You might be interested in posting to the oh so quiet german-language
de.comp.lang.python
Jul 11 '06 #3

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

Similar topics

6
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* ....
4
by: Wes S. | last post by:
How can I redirect and tag sys.stdout values. I tried creating a class module that saved the old stdout and replaced it, but I can't seem to figure out how to do such. Here is what I got... ...
4
by: Leon | last post by:
"stdout" is file object, it open mode is "w" and it have a close() fuction..... while it run close(), how to reopen it because I want to do rewrite it stdout content update
7
by: Mike | last post by:
I would like my 'print' statements to send its output to the user's screen and a log file. This is my initial attempt: class StdoutLog(file): def __init__(self, stdout,...
10
by: Michael Gaab | last post by:
If I redirect stdout by using freopen("afile", "w", stdout); and then I closed stdout using, fclose(stdout), essentially I am just closing "afile". I have to reestablish what stdout originally...
9
by: Santtu Nyrhinen | last post by:
Hi, Let say that I have a function like void writeHello() { printf("Hello"); } Now I need to make an automated test fot that function. The test function returns 1 for successful and 0 for...
2
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import...
5
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I wanna print the log to both the screen and file, so I simulatered a 'tee' class Tee(file): def __init__(self, name, mode): file.__init__(self, name, mode) self.stdout = sys.stdout...
4
by: hg | last post by:
Hi, I have the following ********************* C extention - redir.c #include "Python.h" PyObject * test_redir_test(PyObject *self) {
5
by: Joakim Hove | last post by:
Hello, I have written a program in C; this programs uses an external proprietary library. When calling a certain function in the external library, the particular function writes a message to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.