Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Reading text or csv files and assigning values to variable names

$
0
0

Hi, I have several large text files write out from a VBA program. The files contain numbers only (integers, floating point). I want to read these files into a Julia program. In FORTRAN or VBA you would just use Read(“File.txt (or .csv)”) a, b, c …z where a to z are the variable names. The numerical values in the text file would be automatically assigned to a, b, c in the order they are read.

Is there an equivalent in Julia?

I have spent hours googling but to no avail. The code below works but all the inputs are read into a string s which I guess could be decomposed. Surely there is an easier way as I literally have 100’s of inputs I want to assign to variable names (and possible named tuples)

open(“C:\Users\peter\Documents\Julia_Code\Learning\MyFile.txt”,“r”) do f

 #line_number 
 line = 0   #

# read till end of file 
while ! eof(f)   

   # read a new / next line for every iteration            
    s = readline(f)  
      
   line += 1
    
   println("$s")

end

11 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles