By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

std in and stdout

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.