[Tutor] Output 'Strings' to directory

Danny Yoo dyoo at hashcollision.org
Tue Sep 9 03:15:25 CEST 2014


On Mon, Sep 8, 2014 at 12:17 PM, Felisha Lawrence
<felisha.lawrence at gmail.com> wrote:
> Is it possible to output strings created from a print statement into a
> directory locally?


Hi Felisha,

Yes.  This can be done from the level of your operating system shell,
rather than Python, through "output redirection".

    http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

Output redirection would be an extra-lingual approach to what you're
asking.  It's also fairly straightforward, and works well on Unix-like
systems.  It should also work on Windows, though I have to admit that
I don't have direct experience there.


As an intra-lingual feature, yes as well to your question.  You can
write to a file-like object instead of the systemwide "standard
output".  This requires you to be more specific whenever you're
writing output, to write it to that file.

For example, see the "file" argument to print:

    https://docs.python.org/2/library/functions.html#print

where every place where we'd use a simpler print where it implicitly
prints to the "standard output", we tell it to print to a file.


More information about the Tutor mailing list