【问题标题】:IO.puts elixirs internal representation of a mapIO.puts elixir 地图的内部表示
【发布时间】:2018-04-04 06:59:34
【问题描述】:

我有一张地图map = %{hello: :world}

我可以在控制台中看到长生不老药的内部表示

iex> IO.inspect map
%{hello: :world}

有没有办法将这个内部表示与另一个字符串连接起来?比如:

iex> IO.puts("my map is: #{to_internal_representation(map)}")
my map is %{hello: :world}

【问题讨论】:

    标签: logging elixir


    【解决方案1】:

    Kernel.inspect/1 返回与IO.inspect/1 打印的字符串相同的字符串,因此您可以使用它:

    IO.puts("my map is: #{inspect(map)}")
    

    【讨论】:

      【解决方案2】:

      你可以使用

      IO.inspect(map, label: "my map is")
      => my map is: %{hello: :world}
      

      IO.inspect/2:label 选项将作为您要查看的内容的前缀。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多