如何从Julia中运行的脚本请求用户输入?在MATLAB中,我会这样做:
result = input(prompt)
Run Code Online (Sandbox Code Playgroud)
谢谢
Joh*_*ite 26
最简单的事情是readline(stdin).这就是你要找的东西吗?
Sal*_*apa 17
正如@StefanKarpinski所指出的那样,它将在未来得到解决,这就是我现在所做的:
julia> @doc """
input(prompt::String="")::String
Read a string from STDIN. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a
trailing newline before reading input.
""" ->
function input(prompt::String="")::String
print(prompt)
return chomp(readline())
end
input (generic function with 2 methods)
julia> x = parse(Int, input());
42
julia> typeof(ans)
Int64
julia> name = input("What is your name? ");
What is your name? Ismael
julia> typeof(name)
String
help?> input
search: input
input(prompt::String="")::String
Read a string from STDIN. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a trailing newline before reading input.
julia>
Run Code Online (Sandbox Code Playgroud)