sys.stdout should be redirected to the MATLAB command window. Do you see output with Python's print function?
Example
>> py.print('hello!')
hello!
>>
sys.stderr is not redirected. When you use the functions print_tb and print_exception, you need to tell the functions to write to sys.stdout.
As a debug tip, the exception you catch in MATLAB due to a Python error is a PyException. The PyException has a property ExceptionObject, which is the same result you get from calling sys.exc_info. >> try
py.fractions.Fraction(1,0)
catch e
end
>> e
e =
PyException with properties:
ExceptionObject: [1x1 py.tuple]
identifier: 'MATLAB:Python:PyException'
message: 'Python Error: both arguments should be Rational instances'
cause: {}
stack: [0x1 struct]
>> e.ExceptionObject
ans =
Python tuple with no properties.
(<type 'exceptions.TypeError'>, TypeError('both arguments should be Rational instances',), <traceback object at 0x0000000012AE9A48>)
>> py.traceback.extract_tb(py.operator.getitem(e.ExceptionObject, int32(2)))
ans =
Python list with no properties.
[('C:\\Python27\\lib\\fractions.py', 158, '__new__', 'raise TypeError("both arguments should be "')]
>>
Best Answer