[Tutor] saving output in a text file (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sat Jul 1 19:18:00 CEST 2006


[forwarding to Tutor]

---------- Forwarded message ----------
Date: Sat, 01 Jul 2006 13:58:47 +0400
From: Hafsa raza <hafsaraza at hotmail.com>
To: dyoo at hkn.eecs.berkeley.edu
Subject: Re: [Tutor] saving output in a text file


Thank you for the quick reply. Let me put my question in a more
clearer way for you.

If we want to create a text file and write some text into it we use the
following command in Python:

myfile = open("test.txt","w")<?xml:namespace prefix = o ns =
"urn:schemas-microsoft-com:office:office" />

myfile.write("hello world")

But what if instead of writing the text 'hello world', i want to write
the output returned by a regular expression pattern, into the text file,
how would we specify that in the write command.

Regards,

Hafsa





________________________________________________________________________________
From:  Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
To:  Hafsa raza <hafsaraza at hotmail.com>
CC:  tutor at python.org
Subject:  Re: [Tutor] saving output in a text file
Date:  Fri, 30 Jun 2006 15:04:41 -0700 (PDT)
>    def double(s):
>        "double: string -> string
>        doubles up the input string s."
>        return s + s


Gaah.  Typos.  My apologies.  Here's a correction to double()

     def double(s):
         """double: string -> string
         Doubles up the input string s.  For example, double("abc")
         should return "abcabc".
         """
         return s + s


>Would you be able to write a program that takes "hello world",
runs
>it through double(), and writes out "hello worldhelloworld" to
disk?

I meant to say that the expected content of the file should be:

      "hello worldhello world"

My apologies; I rushed that message too quickly.


________________________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar MSN Toolbar Get it now!


More information about the Tutor mailing list