# Reading an array interactively

**URL:** <https://discourse.julialang.org/t/reading-an-array-interactively/10035>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 28, 2018, 5:52pm UTC](https://discourse.julialang.org/t/reading-an-array-interactively/10035 "2018-03-28T17:52:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramonz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ramonz/32/548_2.png) [@ramonz](https://discourse.julialang.org/u/ramonz)\
**Post date:** [March 28, 2018, 5:52pm UTC](https://discourse.julialang.org/t/reading-an-array-interactively/10035/1 "2018-03-28T17:52:04Z")

</div>

Hello All

I am trying to find a way to input the components of an array of floating numbers (i.e. a vector for a mechanics class examples) interactively. This is the way I am doing it in a notebook

```julia
println("Componentes (3) of vector fx")
fx = zeros(Float64,3)
for i = 1:3
    fx[i] = parse(Float64,readline()) 
end

```

But I was wondering if there is a way to input all values at once, say separated by commas.  
Thanks

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [March 28, 2018, 6:02pm UTC](https://discourse.julialang.org/t/reading-an-array-interactively/10035/2 "2018-03-28T18:02:28Z")

</div>

You could always parse the line as a `String`, and then use [string methods](https://docs.julialang.org/en/latest/base/strings/) such as `split` combined with `parse` to pull individual values out of the strings. So maybe something like

```julia
praseline(str::AbstractString) = parse.(Float64, split(str, " "))

line = readline()
fx = parseline(line)

```

You might be able to find a more direct way using `read(stdin)`, but I don’t know what that would be off the top of my head.

---

<div class="post-metadata">

**Author:** ![ramonz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ramonz/32/548_2.png) [@ramonz](https://discourse.julialang.org/u/ramonz)\
**Post date:** [March 28, 2018, 6:09pm UTC](https://discourse.julialang.org/t/reading-an-array-interactively/10035/3 "2018-03-28T18:09:14Z")

</div>

Thanks ExM  
I am trying it. Need to play around a little.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 28, 2018, 7:50pm UTC](https://discourse.julialang.org/t/reading-an-array-interactively/10035/4 "2018-03-28T19:50:03Z")

</div>

> [@ramonz](#):
>
> But I was wondering if there is a way to input all values at once, say separated by commas.

If you want them comma-separated, you can do `readcsv(IOBuffer(readline()))`.

You can also do `readcsv` directly from stdin, but if you want it to work with a Jupyter notebook then you have to use `readline()`.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [March 28, 2018, 9:08pm UTC](https://discourse.julialang.org/t/reading-an-array-interactively/10035/5 "2018-03-28T21:08:01Z")

</div>

Why do you want to do that? The user can just call an array constructor with their data.

---

<div class="post-metadata">

**Author:** ![ramonz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ramonz/32/548_2.png) [@ramonz](https://discourse.julialang.org/u/ramonz)\
**Post date:** [March 29, 2018, 7:15pm UTC](https://discourse.julialang.org/t/reading-an-array-interactively/10035/6 "2018-03-29T19:15:11Z")

</div>

I want to help the students input the data easily and clearly interactively when asked about the components of the vector. The way I have it now is not so intuitive because the students fill the STDIN box with the three values rather than waiting for the next STDIN box.
