473,748 Members | 2,602 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 1818
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
9918
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
2378
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
7778
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
3705
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
4374
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
3899
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
2102
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
2911
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
8374
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
8984
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
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9238
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
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
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
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
3
2206
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.