[Tutor] How to print to a file? (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Feb 19 14:35:28 EST 2004



---------- Forwarded message ----------
Date: 19 Feb 2004 23:06:02 +0800
From: denny <libsvm at tom.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] How to print to a file?

Thanks a lot for you reply.
It works now.^_^

By the way, how can I install a higher version of python(at least than
python2.2) on RedHat 7.3?
Shall I find one that have complied for the very RedHat 7.3 system?
thanks

=D4=DA 2004-02-19 =CB=C4 =B5=C4 05:16=A3=AC Danny Yoo =D0=B4=B5=C0=A3=BA
> On Wed, 18 Feb 2004, denny wrote:
>
> > I want to write something to a file like this:
> > print >>filehandle, "....%d...%s..."%(num,string)
> > but it raise error
>
> Hi Denny,
>
>
> What kind of error?  Can you show us exactly what the error message looks
> like?  As far as I can tell, the code that you've showed us,
>
>     print >>filehandle, "....%d...%s..." % (num,string)
>
> looks syntactically correct to me.  We really need to see why Python
> doesn't seem to like it; show us the error message, verbatim, and we can
> go from there.
>
>
>
> > Can someone tell me how can I print it above to a file just like we
> > print to the stdout(print "....%d...%s..."(num,string)). Or is there
> > some funtion as we use in C/C++( fprint etc)
>
> The method you tried above should work.
>
>
> Alternatively, you can use the 'write' method of a file object. For
> example, since 'sys.stdout' is a file object, we can say something like:
>
> ###
> sys.stdout.write('hello world\n')
> ###
>
>
>
> Talk to you later!
>
>






More information about the Tutor mailing list