# Reading data of different types from a data file with multiple lines and headers for each line

**URL:** <https://discourse.julialang.org/t/reading-data-of-different-types-from-a-data-file-with-multiple-lines-and-headers-for-each-line/51376>\
**Category:** New to Julia\
**Created:** [December 7, 2020, 3:50am UTC](https://discourse.julialang.org/t/reading-data-of-different-types-from-a-data-file-with-multiple-lines-and-headers-for-each-line/51376 "2020-12-07T03:50:36Z")\
**Posts on this page:** 1\
**Showing post:** 27

<div class="post-metadata">

**Author:** ![FPGro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fpgro/32/20822_2.png) [@FPGro](https://discourse.julialang.org/u/FPGro)\
**Post date:** [December 10, 2020, 10:42am UTC](https://discourse.julialang.org/t/reading-data-of-different-types-from-a-data-file-with-multiple-lines-and-headers-for-each-line/51376/27 "2020-12-10T10:42:36Z")

</div>

> [@Peter-Jolly](#):
>
> ```julia
> @assert length(header) == length(values)
> for (k,v) in zip(header, values)
> output[k] = trytoinfertype(v)
> end
> 
> ```
> 
> How did you know to use these lines? None of the basic documentation material on Julia, I could “google”, would lead me to these lines. It just intrigues me how you knew to insert these lines. How long have been using Julia. ? In “my day” you studied the textbook , got to know the language syntax and proceeded with those tools to master the language … along the way you picked up “tricks” and things to make it easier and write more compact code.  
> […]  
> 3. I have not used Python, but I am guessing Julia and Python are very similar in structure?

Knowing a bit of Python is certainly good to get started with Julia, but it’s not necessary. You could have a look at this, if you have a background in either MATLAB, R, Python, C or Lisp and need a little help for transitioning:

[https://docs.julialang.org/en/v1/manual/noteworthy-differences/](https://docs.julialang.org/en/v1/manual/noteworthy-differences/)

I’ve been using Julia for around a year now, and I’m currently working on my master thesis using Julia, so that helps enormously.

The approach is pretty much the same as in your days: I started by reading the manual and coding up really basic examples and things for fun. It’s of great help to have a kind of ‘toy project’ which you can code up bit by bit, seeing progress when you make it and being able to revise and refactor the code many times. You can be sure that I started writing horrible code (by my current standards) at first 😃 I think I turned the basic bits of my thesis project inside out for the 3rd time now. (I started the project a while ago and it turned into a thesis eventually, it didn’t start as one, else I would have ran out of time by now). [Edit: I’m still far from writing optimal code, but it’s getting better. You’ll get there, too.]

It’s just a process like learning any language. I like revisiting the [docs](https://docs.julialang.org/en/v1/manual/performance-tips/) once in a while, and also looking at the code in Julia Base is often helpful, especially if you implement your own types and need help implementing specialized functions. It’s really helpful to look at how other people solved these problems and digest that.

Oh and reading around the julia discourse here is also pretty helpful, as there are a lot of questions and answers and nice examples here.

> [@Peter-Jolly](#):
>
> 1. Is there a recommended on-line course(s) that would lead one to acquire a comprehensive grasp of the language, such as the code you suggested?

Can’t really help with that, sorry, but similar questions have been asked multiple times here. Maybe you find something there:

> [@A few intermediate Julia tutorials](https://discourse.julialang.org/t/a-few-intermediate-julia-tutorials/41813):
>
> Lately I’ve been writing some Julia tutorials over the weekends to keep my coding skills up. I thought I’d share the repo as it stands today in case anybody’s interested: [https://github.com/johnmyleswhite/julia\_tutorials](https://github.com/johnmyleswhite/julia_tutorials) The tutorials are generally targeted at intermediate users of Julia.

> [@Ensure Julia is used to its full power](https://discourse.julialang.org/t/ensure-julia-is-used-to-its-full-power/51155/80):
>
> I started programming almost 3 decades ago so for me it was kind of normal to learn that by myself, so did I with Julia and other languages. In our university, the coding courses for physicists were basically non-existent when I started studying in 2006. There was a “computational physics” course but it was extremely basic (reading CSV files with C and doing some low level calculations) so I skipped that completely but luckily the computer science department in Erlangen is at the same location …

And finally:

> [@Peter-Jolly](#):
>
> Thanks. Just to be clear the Dictionary method is not as friendly as the struct approach when setting up an ODE solver problem? The Dictionary seems to have the ability to unpack just the specific variables you need for a particular function. Does the struct method offer this targeted ability as well?

Both are fine. With a dictionary holding different types, you need to make sure to annotate the types when you unpack them (for performance reasons), with Nils’ struct approach that comes for free.

Good luck to you!

[Edit: typing errors]

---

_[View the full topic](https://discourse.julialang.org/t/reading-data-of-different-types-from-a-data-file-with-multiple-lines-and-headers-for-each-line/51376)._
