---
title: "Preserve output from python print"
output: md_document
---

```{r}
bt <- reticulate::import_builtins()
bt$print("Hello world")
```

## Print statements should always be captured

In `jupyter_compat = FALSE`: we should only see the output of both expressions.

```{python}
print(1)
print(2)
```

In `jupyter_compat = TRUE`: we should only see the output of both expressions.

```{python, jupyter_compat = TRUE}
print(1)
print(2)
```

## Only outputs of last expressions are captured in jupyter compat

In `jupyter_compat = FALSE`: we should only see the output of both expressions.

```{python}
1 + 0
1 + 1
```

`jupyter_compat = TRUE`: we should only see the output of the last expression.

```{python, jupyter_compat = TRUE}
1 + 0
1 + 1
```

## One can disable outputs by using `;`

In `jupyter_compat = FALSE`: we should only see the print statement output

```{python}
print("hello");
1 + 0;
1 + 1;
```

`jupyter_compat = TRUE`: we should only see the print statement output

```{python, jupyter_compat = TRUE}
print("hello");
1 + 0;
1 + 1;
```

## `jupyter_compat` works with interleaved expressions

```{python, jupyter_compat=TRUE}
print('first_stdout')
'first_expression'
print('second_stdout')
'final_expression'
```


