Newbie: print-to-file-Syntax

Justin Shaw wyojustin at hotmail.com
Sat May 18 15:19:34 EDT 2002


Sabine,
You are close. Note the comma:

print >> PROT, "Printed String"

In order to get the exact behavior of
PROT.write('Printed String') you would need a comma at the end too:

print >> PROT, 'Printed String',

On the other question, I tried this in IDLE
>>> print >> None, 'test'
test
>>>

So it seem to work fine.  Be sure to remember the comma!

Justin

"Sabine Richter" <sabine at textraeume.de> wrote in message
news:mailman.1021745730.10043.python-list at python.org...
> Hello,
>
> I looked the syntax up in the python doc, but nevertheless, I don't
> understand it. What's wrong?
>
> PROT=open("c:\\existing_dir\\prot.txt",'w')
> PROT.write("Written String")
> print >> PROT "Printed String"
> print PROT "Printed String"
>
> PROT.close()
>
> --> Written String has been written. But for the print-Statements I get
> a syntax error message
>
>
> And a second question:
>
> Is it possible to write:
> PROT=None
> print... print-to-file-syntax
>
> Later, I want to print to file, but now I want to print to STDOUT.
> The doc says: If the first expression evaluates to None, then sys.stdout
> is used as the file for output.
>
>
> Thanks in advance
> Sabine
>
>





More information about the Python-list mailing list