I've been working on a project that involves rows of household community data. The records are stored in an Excel file which I converted to a CSV file. This file contains a number of information that must be assigned as attributes of the household agents. Each line represents one agent record with each value separated using a comma. Here's how the data looks like:
1,1,1,1,4,2,2,2,1,3
2,1,2,2,4,2,1,5,1,2
3,1,1,1,1,2,2,7,2,3
4,1,1,1,4,2,1,4,1,1
5,1,1,2,3,4,4,6,1,2
6,1,1,2,4,2,2,3,1,3
7,1,3,2,3,1,3,9,1,4
8,1,2,2,4,4,1,3,1,2
9,1,2,1,4,1,2,5,1,2
10,1,1,1,4,1,5,8,1,2
2,1,2,2,4,2,1,5,1,2
3,1,1,1,1,2,2,7,2,3
4,1,1,1,4,2,1,4,1,1
5,1,1,2,3,4,4,6,1,2
6,1,1,2,4,2,2,3,1,3
7,1,3,2,3,1,3,9,1,4
8,1,2,2,4,4,1,3,1,2
9,1,2,1,4,1,2,5,1,2
10,1,1,1,4,1,5,8,1,2
Below is the openFile procedure which uses two variables, csv to handle the record retrieved per line and fileList to hold all the formatted records (comma separators are removed).
Sample Output:
[[1 1 1 1 4 2 2 2 1 3] [2 1 2 2 4 2 1 5 1 2] [3 1 1 1 1 2 2 7 2 3] [4 1 1 1 4 2 1 4 1 1] [5 1 1 2 3 4 4 6 1 2] [6 1 1 2 4 2 2 3 1 3] [7 1 3 2 3 1 3 9 1 4] [8 1 2 2 4 4 1 3 1 2] [9 1 2 1 4 1 2 5 1 2] [10 1 1 1 4 1 5 8 1 2]]
I made a button for this code. For a four-row table I have to click four times and fileList includes one row each time. Is there a way for fileList to include the whole table in one click and also show the whole table in one click? It seems in each click it read one line.
ReplyDeleteSorry for this late feedback. I am not sure if I get your question right but this code will fetch all the rows from an external file. Did you tick your button configuration to "forever" so that it's going to be executed repeatedly?
DeleteI agree with Elham. Yes the code will import all the row but row by row on each tick (whether it is manual or forever). Elham asked how to show all import data in one click? I also want to ask how to solve errors after the last row imported. The error message:
DeleteThe end of file has been reached
error while observer running FILE-READ-LINE
called by procedure OPENFILE
called by Button 'Open'
Hi.
ReplyDeleteWhat does the $ symbol means? Thanks.
Hi, I understand the code, but I would like save that list in one variable and then assign each value for each turtle.
ReplyDeleteSomeone could help me? please