如何在Elixir中打印PID?
我试图:如何在Elixir中打印PID?,elixir,Elixir,我试图: pid = spawn fn -> 1 + 2 end IO.puts(pid) IO.puts(IO.inspect(pid)) 两人都得到了一个 ** (Protocol.UndefinedError) protocol String.Chars not implemented for #PID<0.59.0> **(Protocol.UndefinedError)协议字符串.Chars未为#PID实现 必须有一种方法来获取PID的“#PID”表示,因为RE
pid = spawn fn -> 1 + 2 end
IO.puts(pid)
IO.puts(IO.inspect(pid))
两人都得到了一个
** (Protocol.UndefinedError) protocol String.Chars not implemented for #PID<0.59.0>
**(Protocol.UndefinedError)协议字符串.Chars未为#PID实现
必须有一种方法来获取
PID
的“#PID”表示,因为REPL打印的是#PID
我发现我使用了错误的inspect
,有和。第二个对我有用:
pid = spawn fn -> 1 + 2 end
IO.puts(inspect(pid))
您不需要在调用
IO.put
时包装IO.inspect。只需调用IO.inspect
即可满足您的需求
pid = spawn fn -> 1 + 2 end
IO.inspect(pid)
只需使用self()
pid=self()
IO.检查(pid)
如果要将其附加到字符串(以显示一些额外的详细信息),可以使用字符串插值:
pid = spawn(fn -> 1 + 2 end)
IO.puts "Pid: #{inspect pid}"
您可以使用inspect
打印大部分内容IO.inspect
只是IO.put(Kernel.inspect(x))