[IPython-User] Pipe into file
Wendell Smith
wackywendell@gmail....
Thu Jul 15 13:45:01 CDT 2010
For Python 3, the syntax is similar:
>>> with open('test.txt','w') as f:
... print('Text',file=f)
...
>>> with open('test.txt') as f:
... print(f.read(), end='')
...
Text
>>>
You can also do this in Python >=2.6 (or ipython) if you start with
from __future__ import print_function
On 07/15/2010 05:45 PM, Max Bane wrote:
> The standard Python print statement supports something like this (not
> sure about Python 3.0, though).
>
> In [1]: f = open('test.txt', 'w')
>
> In [2]: print >> f, 'hello, world'
>
> In [3]: f.close()
>
> In [4]: !cat test.txt
> hello, world
>
>
> On Thu, Jul 15, 2010 at 6:00 AM, Richard Parsons
> <richard.lee.parsons@gmail.com <mailto:richard.lee.parsons@gmail.com>>
> wrote:
>
> How do I pipe the output into a file?
>
> I want to do this, but it doesn't work...
>
> print variable > some_filename
>
> Thanks,
> Richard
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org <mailto:IPython-User@scipy.org>
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>
>
>
> --
> Max Bane
> PhD Student, Linguistics
> University of Chicago
> bane@uchicago.edu <mailto:bane@uchicago.edu>
>
>
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20100715/94560e4e/attachment.html
More information about the IPython-User
mailing list