Re: (3.2) Overload print() using the C API?

2012-04-28 Thread Stefan Behnel
Peter Faulks, 27.04.2012 22:31: > On 27/04/2012 6:55 PM, Stefan Behnel wrote: >> Peter Faulks, 27.04.2012 10:36: >>> On 27/04/2012 5:15 PM, Stefan Behnel wrote: Peter Faulks, 26.04.2012 19:57: > I want to extend an embedded interpreter so that calls to print() are > automagically sent

Re: (3.2) Overload print() using the C API?

2012-04-27 Thread Peter Faulks
On 27/04/2012 6:55 PM, Stefan Behnel wrote: Peter Faulks, 27.04.2012 10:36: On 27/04/2012 5:15 PM, Stefan Behnel wrote: Peter Faulks, 26.04.2012 19:57: I want to extend an embedded interpreter so that calls to print() are automagically sent to a C++ gui (windows exe) via a callback function in

Re: (3.2) Overload print() using the C API?

2012-04-27 Thread Terry Reedy
On 4/27/2012 4:55 AM, Stefan Behnel wrote: I want the script itself to update a window in the host application (via the extension) every time the script calls print(). Then replace sys.stdout (and maybe also sys.stderr) by another object that does what you want whenever its write() method is c

Re: (3.2) Overload print() using the C API?

2012-04-27 Thread Stefan Behnel
Peter Faulks, 27.04.2012 10:36: > On 27/04/2012 5:15 PM, Stefan Behnel wrote: >> Peter Faulks, 26.04.2012 19:57: >>> I want to extend an embedded interpreter so that calls to print() are >>> automagically sent to a C++ gui (windows exe) via a callback function in >>> the DLL. >>> >>> Then I'll be a

Re: (3.2) Overload print() using the C API?

2012-04-27 Thread Peter Faulks
On 27/04/2012 5:15 PM, Stefan Behnel wrote: Peter Faulks, 26.04.2012 19:57: I want to extend an embedded interpreter so that calls to print() are automagically sent to a C++ gui (windows exe) via a callback function in the DLL. Then I'll be able to do this: test.py import printoverload

Re: (3.2) Overload print() using the C API?

2012-04-27 Thread Stefan Behnel
Peter Faulks, 26.04.2012 19:57: > I want to extend an embedded interpreter so that calls to print() are > automagically sent to a C++ gui (windows exe) via a callback function in > the DLL. > > Then I'll be able to do this: > > test.py > import printoverload > > printoverload.set_stdout(

Re: (3.2) Overload print() using the C API?

2012-04-27 Thread Stefan Behnel
Peter Faulks, 26.04.2012 21:28: > "All you have to do is assign to print". Sounds great! Can some kind soul > hit me with a clue stick? Were do I look in the API? Here's the (Py3) Cython code for it: print = my_print_function Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: (3.2) Overload print() using the C API?

2012-04-26 Thread Chris Angelico
On Fri, Apr 27, 2012 at 5:28 AM, Peter Faulks wrote: > Cheers, > > Yes was aware this would (might) be possible in 3.x only. > > "All you have to do is assign to print". Sounds great! Can some kind soul > hit me with a clue stick? Were do I look in the API? (We prefer to avoid top-posting on this

Re: (3.2) Overload print() using the C API?

2012-04-26 Thread Peter Faulks
Cheers, Yes was aware this would (might) be possible in 3.x only. "All you have to do is assign to print". Sounds great! Can some kind soul hit me with a clue stick? Were do I look in the API? On 27/04/2012 4:26 AM, Chris Angelico wrote: On Fri, Apr 27, 2012 at 3:57 AM, Peter Faulks wrote

Re: (3.2) Overload print() using the C API?

2012-04-26 Thread Chris Angelico
On Fri, Apr 27, 2012 at 3:57 AM, Peter Faulks wrote: > I want to extend an embedded interpreter so that calls to print() are > automagically sent to a C++ gui (windows exe) via a callback function in the > DLL. > > Then I'll be able to do this: > > test.py > import printoverload > > printo

(3.2) Overload print() using the C API?

2012-04-26 Thread Peter Faulks
G'day, I want to extend an embedded interpreter so that calls to print() are automagically sent to a C++ gui (windows exe) via a callback function in the DLL. Then I'll be able to do this: test.py import printoverload printoverload.set_stdout() printoverload.set_stderr() print("th

Re: Overload print

2010-08-27 Thread genxtech
On Aug 25, 5:18 pm, Ross Williamson wrote: > Hi All > > Is there anyway in a class to overload the print function? > > >> class foo_class(): > >>      pass > >> cc = foo_class() > >> print cc > > Gives: > > <__main__.foo_class instance at > > > Can I do something like: > > >> class foo_class()

Re: Overload print

2010-08-26 Thread John Roth
ves: > > > hello > > Hmm, on what Python version are you? To my knowledge there is no > __print__ special method. Did you mean __str__ or __repr__ ? > > > I'm looking at finding nice way to print variables in a class just by > > asking to print it > > In Pyt

Re: Overload print

2010-08-25 Thread Chris Kaynor
On Wed, Aug 25, 2010 at 2:23 PM, Glenn Hutchings wrote: > On 25 Aug, 22:18, Ross Williamson > wrote: > > Is there anyway in a class to overload the print function? > > > > >> class foo_class(): > > >> pass > > >> cc = foo_class() > > >> print cc > > > > Gives: > > > > <__main__.foo_class in

Re: Overload print

2010-08-25 Thread Alexander Kapps
les in a class just by asking to print it In Python3 you *can* overload print(), but still, you better define __str__() on your class to return a string, representing what ever you want: In [11]: class Foo(object): : def __str__(self): : return "foo"

Re: Overload print

2010-08-25 Thread D'Arcy J.M. Cain
On Wed, 25 Aug 2010 16:18:15 -0500 Ross Williamson wrote: > Hi All > > Is there anyway in a class to overload the print function? Your terminology threw me off for a moment. You don't want to override print. You want to override the default representation of an object. > > >> class foo_class

Re: Overload print

2010-08-25 Thread Chris Rebert
On Wed, Aug 25, 2010 at 2:18 PM, Ross Williamson wrote: > Hi All > > Is there anyway in a class to overload the print function? > >>> class foo_class(): >>>      pass > >>> cc = foo_class() >>> print cc > > Gives: > > <__main__.foo_class instance at > > > Can I do something like: > >>> class f

Re: Overload print

2010-08-25 Thread Glenn Hutchings
On 25 Aug, 22:18, Ross Williamson wrote: > Is there anyway in a class to overload the print function? > > >> class foo_class(): > >>      pass > >> cc = foo_class() > >> print cc > > Gives: > > <__main__.foo_class instance at > > > Can I do something like: > > >> class foo_class(): > >>     de

Overload print

2010-08-25 Thread Ross Williamson
Hi All Is there anyway in a class to overload the print function? >> class foo_class(): >> pass >> cc = foo_class() >> print cc Gives: <__main__.foo_class instance at > Can I do something like: >> class foo_class(): >> def __print__(self): >> print "hello" >> cc = foo