Forwarding to tutor.
---------- Forwarded message ----------
From: "Felisha Lawrence" <felisha.lawre...@gmail.com>
Date: Sep 9, 2014 6:56 AM
Subject: Re: [Tutor] Output 'Strings' to directory
To: "Danny Yoo" <d...@hashcollision.org>
Cc:

> So, I ran the following code
>
>
> import os
>
> path = '/Users/felishalawrence/testswps/vol1'
> for file in os.listdir(path):
>         newFile = file[:file.rindex("v")]+"v20"
> sys.stdout =  '/Users/felishalawrence/testswps/vol1'
> print newFile
>
> and got nothing. No errors and it did not print out my results in ipython
notebook when I removed line 5 and ran it again. The output was also not in
the folder specified. What did I do wrong?
>
> Thanks,
>
>
>
> On Mon, Sep 8, 2014 at 9:15 PM, Danny Yoo <d...@hashcollision.org> wrote:
>>
>> On Mon, Sep 8, 2014 at 12:17 PM, Felisha Lawrence
>> <felisha.lawre...@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.
>
>
>
>
> --
> Felisha Lawrence
> Howard University Program for Atmospheric Sciences(HUPAS), Graduate
Student
> NASA URC/BCCSO Graduate Fellow
> NOAA NCAS Graduate Fellow
> Graduate Student Association for Atmospheric Sciences(GSAAS), Treasurer
> (240)-535-6665 (cell)
> felisha.lawre...@gmail.com (email)
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to