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 to a C++ gui

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-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 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

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 able to do this:

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

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

(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()

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 faul...@iinet.net.au 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

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

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 faul...@iinet.net.au 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

Re: Overload print

2010-08-27 Thread genxtech
On Aug 25, 5:18 pm, Ross Williamson rosswilliamson@gmail.com 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

Re: Overload print

2010-08-26 Thread John Roth
variables 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

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_class() print cc

Re: Overload print

2010-08-25 Thread Glenn Hutchings
On 25 Aug, 22:18, Ross Williamson rosswilliamson@gmail.com 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():    

Re: Overload print

2010-08-25 Thread Chris Rebert
On Wed, Aug 25, 2010 at 2:18 PM, Ross Williamson rosswilliamson@gmail.com 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

Re: Overload print

2010-08-25 Thread D'Arcy J.M. Cain
On Wed, 25 Aug 2010 16:18:15 -0500 Ross Williamson rosswilliamson@gmail.com 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

Re: Overload print

2010-08-25 Thread Alexander Kapps
* 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 : : In [12]: f = Foo() In [13]: print f foo -- http://mail.python.org

Re: Overload print

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