Skip to content

Display for pytype in Pluto notebooks #101

Closed
@icweaver

Description

@icweaver

pytype seems to throw the following for me in a Pluto notebook:

using PythonCall

x_py = pylist([1, 2, 3])
# x_py = Python list: [1, 2, 3]

pytype(x_py)
Failed to show value:

MethodError: no method matching show(::IOContext{IOBuffer}, ::Nothing, ::PythonCall.Py)

Closest candidates are:

show(::IO, !Matched::AbstractString, ::Any) at ~/julia-1.7.1/share/julia/base/multimedia.jl:111
show(::IO, !Matched::MIME{Symbol("text/csv")}, ::PythonCall.Py) at ~/.julia/packages/PythonCall/59kNC/src/Py.jl:266
show(::IO, !Matched::MIME{Symbol("text/csv")}, ::Any) at ~/julia-1.7.1/share/julia/stdlib/v1.7/DelimitedFiles/src/DelimitedFiles.jl:829
...
    1. show_richest(::IOContext{IOBuffer}, ::Any)@PlutoRunner.jl:1019
    2. var"#sprint_withreturned#54"(::IOContext{Base.DevNull}, ::Int64, ::typeof(Main.PlutoRunner.sprint_withreturned), ::Function, ::PythonCall.Py)@PlutoRunner.jl:954
    3. format_output_default(::Any, ::Any)@PlutoRunner.jl:862
    4. var"#format_output#42"(::IOContext{Base.DevNull}, ::typeof(Main.PlutoRunner.format_output), ::Any)@PlutoRunner.jl:879
    5. formatted_result_of(::Base.UUID, ::Bool, ::Vector{String}, ::Nothing, ::Module)@PlutoRunner.jl:785
    6. top-level scope@none:1

while printing to plain text looks to work fine I think:

println(pytype(x_py)) # <class 'list'>

albeit the display is slightly different than just running it directly in the REPL:

julia> using PythonCall
    
julia> x_py = pylist([1, 2, 3])
Python list: [1, 2, 3]

julia> pytype(x_py)
Python type: <class 'list'>

Loving all the new updates by the way!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions