473,396 Members | 1,996 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.

Help with python output redirection

Here is the basic code (yes, I know its tiny).

x = ['print "x =", x', 'for m in x: print m']
print "x =", x
for m in x: print m

I want to modify this so it will output to a file called 1. What I want
is to have that file direct its output to a file called 2 and 2 direct
to 3 and so on. Hopefully this will be an easy-to-answer question. THX
in advance.

Apr 15 '06 #1
7 1802
On Fri, 14 Apr 2006 16:59:13 -0700, fatalserpent wrote:
Here is the basic code (yes, I know its tiny).

x = ['print "x =", x', 'for m in x: print m']
print "x =", x
for m in x: print m

I want to modify this so it will output to a file called 1. What I want
is to have that file direct its output to a file called 2 and 2 direct
to 3 and so on. Hopefully this will be an easy-to-answer question. THX
in advance.


From the shell, you are probably doing something like this:

$ python mymodule.py

Change it to this:

$ python mymodule.py > 2
$ python 2 > 3
$ python 3 > 4

and so on.

Alternatively, you can do this:

x = ['f = file("2", "w")', 'print >>f, "x =", x',
'for m in x: >>f, print m']
print >>f, "x =", x
for m in x: print >>f, m

I'll leave changing the file name from "2" to "3" etc. as an exercise for
you.
--
Steven.

Apr 15 '06 #2
Thank you. Also this script is PublicDomain right?
Steven D'Aprano wrote:
On Fri, 14 Apr 2006 16:59:13 -0700, fatalserpent wrote:
Here is the basic code (yes, I know its tiny).

x = ['print "x =", x', 'for m in x: print m']
print "x =", x
for m in x: print m

I want to modify this so it will output to a file called 1. What I want
is to have that file direct its output to a file called 2 and 2 direct
to 3 and so on. Hopefully this will be an easy-to-answer question. THX
in advance.


From the shell, you are probably doing something like this:

$ python mymodule.py

Change it to this:

$ python mymodule.py > 2
$ python 2 > 3
$ python 3 > 4

and so on.

Alternatively, you can do this:

x = ['f = file("2", "w")', 'print >>f, "x =", x',
'for m in x: >>f, print m']
print >>f, "x =", x
for m in x: print >>f, m

I'll leave changing the file name from "2" to "3" etc. as an exercise for
you.
--
Steven.


Apr 15 '06 #3
On 16/04/2006 12:36 AM, fatal.serpent top-posted:
Thank you. Also this script is PublicDomain right?
Wrong. If you attempt to turn "The D'Aprano Code" into a best-seller,
and don't donate assign all of your royalties to the PSF, they will
pursue you and your descendants to the ends of the universe.
Steven D'Aprano wrote:
On Fri, 14 Apr 2006 16:59:13 -0700, fatalserpent wrote:
[snip] From the shell, you are probably doing something like this:

$ python mymodule.py

Change it to this:

$ python mymodule.py > 2
$ python 2 > 3
$ python 3 > 4

and so on.

Alternatively, you can do this:

x = ['f = file("2", "w")', 'print >>f, "x =", x',
'for m in x: >>f, print m']
print >>f, "x =", x
for m in x: print >>f, m

I'll leave changing the file name from "2" to "3" etc. as an exercise for
you.
--
Steven.

Apr 15 '06 #4
On Sat, 15 Apr 2006 07:36:30 -0700, fatal.serpent wrote:
Thank you. Also this script is PublicDomain right?
Oh heavens, I never even thought about that... the world was a much better
place when you actually needed to *claim copyright* rather than just have
it apply automatically on every stupid little doodle or comment.

I've heard from authorities I trust that under US law private citizens
can't "not copyright" something you write, even if you want it to go into
the Public Domain. I've also heard the opposite from experts I equally
trust.

So, let me say firstly that I wish the following code to be put into
the public domain, and if there is any reason why it has not been, I
hereby give everybody an unlimited, non-exclusive, transferable, free of
all charges and royalties, licence to use the following code in any way
they see fit, with no conditions attached except there is no warranty. You
don't even have to credit me. If you try to make a warranty claim against
me for this code, the licence is instantly revoked.

There. It probably won't stand up in a court of law, but I promise not to
sue if you promise the same.
Steven D'Aprano wrote:
On Fri, 14 Apr 2006 16:59:13 -0700, fatalserpent wrote:
> Here is the basic code (yes, I know its tiny).
>
> x = ['print "x =", x', 'for m in x: print m']
> print "x =", x
> for m in x: print m
>
> I want to modify this so it will output to a file called 1. What I want
> is to have that file direct its output to a file called 2 and 2 direct
> to 3 and so on. Hopefully this will be an easy-to-answer question. THX
> in advance.


From the shell, you are probably doing something like this:

$ python mymodule.py

Change it to this:

$ python mymodule.py > 2
$ python 2 > 3
$ python 3 > 4

and so on.

Alternatively, you can do this:

x = ['f = file("2", "w")', 'print >>f, "x =", x',
'for m in x: >>f, print m']
print >>f, "x =", x
for m in x: print >>f, m

I'll leave changing the file name from "2" to "3" etc. as an exercise for
you.
--
Steven.


--
Steven.

Apr 16 '06 #5
Steven D'Aprano wrote:
So, let me say firstly that I wish the following code to be put into
the public domain


so you're taking the work by others ("for m in x", "print m", and so on)
and think that by posting it to usenet as if you wrote it yourself, you
can release it into the public domain ?

</F>

Apr 16 '06 #6
Fredrik Lundh wrote:
Steven D'Aprano wrote:
So, let me say firstly that I wish the following code to be put into
the public domain


so you're taking the work by others ("for m in x", "print m", and so on)
and think that by posting it to usenet as if you wrote it yourself, you
can release it into the public domain ?


I don't think there's a judge in the world that would think those few characters
are copyrightable by themselves.

--
Robert Kern
ro*********@gmail.com

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Apr 16 '06 #7
On Sun, 16 Apr 2006 12:16:39 +0200, Fredrik Lundh wrote:
Steven D'Aprano wrote:
So, let me say firstly that I wish the following code to be put into
the public domain


so you're taking the work by others ("for m in x", "print m", and so on)
and think that by posting it to usenet as if you wrote it yourself, you
can release it into the public domain ?


???

You're joking, right?

Look, I'm not having a good run at the moment telling when folks are being
funny, so if you trying to introduce a note of levity into the discussion,
ha ha I laughed so much my sides burst.

But if you are being serious, and for the benefit of anyone else out there
who doesn't get the joke and thinks there is something of substance to
your claim:

(1) If I didn't already have the copyright to the code, I simply can't
transfer ownership to it or reassign copyright no matter what I say;

(2) If you read my post, I think it is abundantly clear that my intention
was not to claim copyright on it at all;

(3) Only because the Original Poster appeared to be concerned about
copyright on the code I posted, I released it, simply to reassure the OP;

(4) As far as me posting individual Python statements (like for, print
etc.) as if I wrote them myself, that's ludicrous. A writer's copyright on
a work does not imply copyright on the individual words; likewise a
programmer's copyright on a program does not mean he claims copyright on
the language itself.

So, just so there is no misunderstanding:

- I did not write the Python language, I do not have ownership of the
copyright to the Python language, and it is not my intention to transfer
copyright of the Python language (in whole or in part) to the public
domain, even if I were able to, which I am not.

- I do not have copyright on any code not written by me, consequently I'm
not releasing the copyright on any code not written by me.

- I am, however, explicitly releasing from copyright the code written by
me in the earlier message with the subject line "Re: Help with python
output redirection" dated Sat, 15 Apr 2006 12:09:17 +1000, and then
re-posted as quoted text in a message with the same subject line dated
Sun, 16 Apr 2006 11:35:04 +1000.

- In the event that the appropriate laws do not allow me to release from
copyright the code, I offer it to anyone who wants to copy such a trivial
few lines of code into their own work with an unlimited, non-exclusive,
transferable, warranty-less licence.

- None of this is a substitute for paying a lawyer many hundreds of
dollars to be told that no judge is going to rule copyright infringement
for copying such a trivial work, and that this whole exercise was an utter
waste of time.
Sheesh. I have to deal with enough legal waffle at work, I didn't think
I'd be held to such pedantic standards about a trivial four-line piece of
code on Usenet.

Oh, Fredrik, if your intention was to demonstrate just what a PITA overly
strict copyright law is, you're preaching to the converted brother.
--
Steven.

Apr 16 '06 #8

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

Similar topics

4
by: Christian Long | last post by:
Hi I'm trying to pipe data into a python program on Windows 2000, on the command line. Like this: dir | myProgram.py Here's what I tried:
1
by: Kumbale, Murali T. | last post by:
I am new to Python and redirection etc. I created a simple COM object in Visual FORTRAN called "disp.disp" that writes to the WINDOWS console. I wrote a Python script which looks like the...
3
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
3
by: Liren Zhao | last post by:
I use some "Console.WriteLine(some strings here)" to display some debug information in my winform program. How can I get the information in my programe or same them in a text file ?
53
by: Michael Tobis | last post by:
Someone asked me to write a brief essay regarding the value-add proposition for Python in the Fortran community. Slightly modified to remove a few climatology-related specifics, here it is. I...
4
by: Barry | last post by:
Hi, guys Basiclly, it is automated testing system. There is a main python script that handles the testing campagin. This main script will call another script that will in turn runs a few...
3
by: Doru Moisa | last post by:
Hello, How can I capture the output of a long runnning process which I open with popen() ? I tried reading line by line, char by char, but the result always comes when the process finishes. (I...
3
by: koutoo | last post by:
Is it possible to display messages in the python shell? I want to display error messages based on parameters in my scripts to the users. Is there another way to display messages other than log...
1
by: TP | last post by:
Hi everybody, I try to find a quick way to redirect the standard output of a Python command (for example: print "message") to a python variable "foobar". Ok, in this simple example, I could do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.