It’s something to do with the print statement.
print( String(take!(buf)) )
This is what buf actually looks like if don’t print it out and just use
String(take!(buf))
the python code
digit = 0
while digit<=255:
print("%d = %c" %(digit, chr(digit)))
digit += 1
print("done")
the julia code
$julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.7.0 (2021-11-30)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> using PyCall
julia> buf = IOBuffer()
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1)
julia> pyimport("sys").stdout = buf
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1)
julia> @pyinclude("test_stdout_pycall.py")
julia> pyimport("sys")."stdout".flush()
julia> String(take!(buf))
"0 = \0\n1 = \x01\n2 = \x02\n3 = \x03\n4 = \x04\n5 = \x05\n6 = \x06\n7 = \a\n8 = \b\n9 = \t\n10 = \n\n11 = \v\n12 = \f\n13 = \r\n14 = \x0e\n15 = \x0f\n16 = \x10\n17 = \x11\n18 = \x12\n19 = \x13\n20 = \x14\n21 = \x15\n22 = \x16\n23 = \x17\n24 = \x18\n25 = \x19\n26 = \x1a\n27 = \e\n28 = \x1c\n29 = \x1d\n30 = \x1e\n31 = \x1f\n32 = \n33 = !\n34 = \"\n35 = #\n36 = \$\n37 = %\n38 = &\n39 = '\n40 = (\n41 = )\n42 = *\n43 = +\n44 = ,\n45 = -\n46 = .\n47 = /\n48 = 0\n49 = 1\n50 = 2\n51 = 3\n52 = 4\n53 = 5\n54 = 6\n55 = 7\n56 = 8\n57 = 9\n58 = :\n59 = ;\n60 = <\n61 = =\n62 = >\n63 = ?\n64 = @\n65 = A\n66 = B\n67 = C\n68 = D\n69 = E\n70 = F\n71 = G\n72 = H\n73 = I\n74 = J\n75 = K\n76 = L\n77 = M\n78 = N\n79 = O\n80 = P\n81 = Q\n82 = R\n83 = S\n84 = T\n85 = U\n86 = V\n87 = W\n88 = X\n8" ⋯ 768 bytes ⋯ "180 = ´\n181 = µ\n182 = ¶\n183 = ·\n184 = ¸\n185 = ¹\n186 = º\n187 = »\n188 = ¼\n189 = ½\n190 = ¾\n191 = ¿\n192 = À\n193 = Á\n194 = Â\n195 = Ã\n196 = Ä\n197 = Å\n198 = Æ\n199 = Ç\n200 = È\n201 = É\n202 = Ê\n203 = Ë\n204 = Ì\n205 = Í\n206 = Î\n207 = Ï\n208 = Ð\n209 = Ñ\n210 = Ò\n211 = Ó\n212 = Ô\n213 = Õ\n214 = Ö\n215 = ×\n216 = Ø\n217 = Ù\n218 = Ú\n219 = Û\n220 = Ü\n221 = Ý\n222 = Þ\n223 = ß\n224 = à\n225 = á\n226 = â\n227 = ã\n228 = ä\n229 = å\n230 = æ\n231 = ç\n232 = è\n233 = é\n234 = ê\n235 = ë\n236 = ì\n237 = í\n238 = î\n239 = ï\n240 = ð\n241 = ñ\n242 = ò\n243 = ó\n244 = ô\n245 = õ\n246 = ö\n247 = ÷\n248 = ø\n249 = ù\n250 = ú\n251 = û\n252 = ü\n253 = ý\n254 = þ\n255 = ÿ\ndone\n"
julia>