gpt4 book ai didi

elixir - 如何在长列表上使用 IO.inspect 而不对其进行修剪?

转载 作者:行者123 更新时间:2023-12-03 07:38:13 25 4
gpt4 key购买 nike

当我这样做时:

IO.inspect [:right, :top, :left, ...very_long_list]

我只得到第一个项目(这是解决 15 个谜题的 Action 列表),如下所示:

[:right, :top, :left, :bot, :bot, :left, :top, :top, :right, :right, :bot,
:left, :bot, :left, :top, :right, :bot, :right, :top, :top, :left, :bot,
:left, :top, :right, :right, :bot, :bot, :left, :top, :top, :left, :bot,
:right, :top, :right, :bot, :left, :left, :top, :right, :bot, :right, :top,
:left, :left, :bot, ...] # => See the '...'
instead, I would like
to get the complete list

我如何告诉IO.inspect不要修剪列表?有什么选择吗?

最佳答案

参见Inspect.Opts有关可用选项的说明:

  • :limit - limits the number of items that are printed for tuples, bitstrings, maps, lists and any other collection of items. It does not apply to strings nor charlists and defaults to 50. If you don't want to limit the number of items to a particular number, use :infinity.

因此您可以通过 limit: :infinity 来打印所有元素:

IO.inspect(list, limit: :infinity)

对于字符串和字符列表,有一个名为 :printable_limit 的特殊选项。这两个选项可以组合起来,以确保所有元素都完全打印。

关于elixir - 如何在长列表上使用 IO.inspect 而不对其进行修剪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29566248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com