473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1814
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*********@gma il.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 misunderstandin g:

- 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
9912
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
2375
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 following import win32com.client o = win32com.client.Dispatch("disp.disp") o.SimpeAdd(5) SimpleAdd method takes the argument supplied (the number 5 in this case) and adds 10 to it and then writes to FORTRAN standard output using
3
7775
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. The obvious way to do this is by using the static Console type properties, In and Out. When trying to debug the app in the IDE however, this doesn't appear to work. I've edited the project properties and added the necessary text to the "command...
3
3702
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
4354
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 would welcome comments and corrections, and would be happy to contribute some version of this to the Python website if it is of interest. ===
4
3896
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 hundered individual python scripts. Here is my problem. I want to log everything displayed in the screen after I start the main python script. Things include unhandled exceptions , message from print statement and other sources.
3
2099
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 am trying to make a wx.python program that opens some "make ..." with popen). How can I receive the output of the program immediatly, so that I can show a progressbar in my application ? I always get the program's output after it finished...
3
2908
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 files? Thanks. Kou
1
8367
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 foobar = "message", but in fact 'print "message"' could be replaced by any Python function writing on standard output. I have googled on this subject. To redirect to a variable, I could use a temporary file:
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.