On Thu, 6 May 2010 09:45:25 -0500
"Edward K. Ream" <
edre...@gmail.com> wrote:
> On Fri, Apr 23, 2010 at 9:51 AM, Terry Brown <
terry_...@yahoo.com> wrote:
> > On Fri, 23 Apr 2010 07:40:33 -0700 (PDT)
> > Nick_H <
n...@plextek.co.uk> wrote:
> >
> >> AttributeError: 'NoneType' object has no attribute 'write'
> >> )
> >>
> >> I can always just use python.exe with the console window, but is there
> >> a way I can fix this?
> >
> > Leo has a tendency to chatter on the console window, you'd probably need to study the code to work out the best way to avoid problems when there's no stdout / stderr.
> >
> > I think we're basically seeing this error:
> >
> >>>> import sys
> >>>> sys.stdout = None
> >>>> print 'test'
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > AttributeError: 'NoneType' object has no attribute 'write'
> >
> > I think all occurrences of 'print' were eliminated from the core code, there are probably some lurking in some plugins (mea culpa). So the most general fix might be for Leo to create dummy files on sys.stdout etc. if they're None.
>
> I am a bit lost here. Problems with print vs. print() should give
> syntax errors, not runtime errors. Furthermore, I just verified that
> one can run launchleo.py from python26/pythonw.exe. Thus, I don't
> understand either the problem or the proposed solution :-)
Printing in Python 2k and 3k behaves differently when sys.stdout == None. 2k raises an AttributeError (i.e. sys.stdout.write(foo) fails), whereas 3k just does nothing, no output or error. There are a small number of places in plugins, and possibly the core also, where 2k style print is used, just launching leo isn't enough to trigger the problem. So changing those to whatever it is that you're supposed to use in leo code instead of print (some g. function I imagine) would probably fix the problem, as long as the g. function itself didn't trip over the sys.stdout == None case.
Just changing print foo to print(foo) is insufficient, because 2k will still trip on sys.stdout == None, and besides printing a tuple adds parentheses to the output.