Acceda a argumentos de línea de comandos en Julia
Cuando escribo
$ julia myprog.jl foo bar baz
¿En qué parte de mi código puedo acceder a las cadenas "foo", "bar", "baz"
?
Estoy buscando el equivalente en Python de sys.argv
23
2 answers
Ah, más búsquedas en la web llevaron a la respuesta correcta. La palabra clave ARGS::Array{ASCIIString}
contiene argumentos de línea de comandos
Aquí hay un ejemplo simple
# cli.jl
print(map(x->string(x, x), ARGS)) # Concatenate each arg onto itself and print
Vamos a probarlo en la línea de comandos:
$ julia cli.jl a b c
aa
bb
cc
24
Author: MRocklin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-11 16:15:46
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-11 16:15:46
Un ejemplo más simple:
#printargs.jl
Println (ARGS[2]);
Ejecutarlo como
Julia printargs.jl a b c d
B
Tenga en cuenta que el índice del array comienza desde 1 y NO 0. Así, ARGS[2] imprime b y no c como en el caso de muchos otros lenguajes de programación.
14
Author: Ayush,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-16 02:01:42
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-16 02:01:42