Skip to content

Commit 522ebbe

Browse files
committed
Document round-trip behavior for bytes conversion
1 parent 526fbac commit 522ebbe

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

docs/type-conversion.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ py:call(image_processor, load, [{bytes, ImageData}]).
7676
This is useful when you need to ensure binary data is treated as raw bytes in Python,
7777
for example when working with binary protocols, image data, or compressed content.
7878

79+
Note that on the return path, both Python `str` and `bytes` become Erlang `binary()`:
80+
81+
```erlang
82+
%% Python str -> Erlang binary
83+
{ok, <<"hello">>} = py:eval(<<"'hello'">>).
84+
85+
%% Python bytes -> Erlang binary
86+
{ok, <<"hello">>} = py:eval(<<"b'hello'">>).
87+
88+
%% Non-UTF8 bytes also work
89+
{ok, <<255, 254>>} = py:eval(<<"b'\\xff\\xfe'">>).
90+
```
91+
7992
## Python to Erlang
8093

8194
Return values from Python are converted back to Erlang:

0 commit comments

Comments
 (0)