c++调用python输出调试信息
时间: 2023-10-23 20:12:21 浏览: 177
C++调用Python
4星 · 用户满意度95%
在Python中,可以使用`print()`函数来输出调试信息。例如:
```python
def my_function(x, y):
print("x =", x)
print("y =", y)
result = x + y
print("result =", result)
return result
my_function(2, 3)
```
输出:
```
x = 2
y = 3
result = 5
```
也可以使用`logging`模块来输出调试信息,这样可以更加灵活地控制输出级别和输出位置。例如:
```python
import logging
def my_function(x, y):
logging.debug("x = %d", x)
logging.debug("y = %d", y)
result = x + y
logging.debug("result = %d", result)
return result
logging.basicConfig(level=logging.DEBUG)
my_function(2, 3)
```
输出:
```
DEBUG:root:x = 2
DEBUG:root:y = 3
DEBUG:root:result = 5
```
阅读全文