[Tutor] nul file in Windows
Wayne Werner
waynejwerner at gmail.com
Sun Nov 15 14:52:35 CET 2009
On Sun, Nov 15, 2009 at 6:39 AM, Timo List <timomlists at gmail.com> wrote:
> For my program I disable the py2exe log feature by routing output to the
> nul-file.
> Code:
>
> if win32 and py2exe:
> sys.stdout = open("nul", "w")
> sys.stderr = open("nul", "w")
>
> This always worked fine.
>
> Today, I received an email from a user with the following error:
> IOError: [Errno 2] No such file or directory: 'nul'
>
> Now, I thought the nul-file always existed, shouldn't it?
> Is there another way to disable output, if this one fails?
>
Just try/except:
try:
#put your code here
except IOError:
#don't save, print a message, whatever you want to do
#if you want to propagate the error, uncomment next line
#raise
HTH,
Wayne
--
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091115/54432597/attachment-0001.htm>
More information about the Tutor
mailing list