NetLogo 无法在每个 运行 之前加载 CSV
NetLogo cannot load CSV before every run
我是 NetLogo 的新手,正在尝试导入带有州坐标的 CSV。我使用了这里给出的代码,它工作正常。唯一的问题是我必须关闭 Netlogo 和 运行 我的代码才能得到我的输出。如果我再运行它,它不起作用,除非我关闭软件!
我调试了我的代码,发现它没有进入多个 运行 的 while [not file-at-end?]
循环。这是一种奇怪的行为。我已经初始化了我所有的列表和变量,并且也全部重置了。感谢任何帮助。
我的代码:
to load-physician-file
file-open "Physician-File.csv"
while [not file-at-end?]
[
set csv file-read-line
set csv word csv ","
set fileList[]
while [not empty? csv]
[
let $x position "," csv
let $item substring csv 0 $x
carefully [set $item read-from-string $item] []
set fileList lput $item fileList
set csv substring csv ($x + 1) length csv
]
set State-abbrev item 0 fileList
if label-states
[
create-state-labels 1
[
set xcor (item 2 filelist - 1.6)
set ycor (item 1 fileList - 1.6)
set size 0
set label item 0 fileList
]
]
]
file-close
end
我强烈怀疑您遗漏了 file-close
或 file-close-all
。
也许与预期相反,clear-all
不会关闭文件,file-open
return 也不会关闭已打开文件的开头。
我是 NetLogo 的新手,正在尝试导入带有州坐标的 CSV。我使用了这里给出的代码,它工作正常。唯一的问题是我必须关闭 Netlogo 和 运行 我的代码才能得到我的输出。如果我再运行它,它不起作用,除非我关闭软件!
我调试了我的代码,发现它没有进入多个 运行 的 while [not file-at-end?]
循环。这是一种奇怪的行为。我已经初始化了我所有的列表和变量,并且也全部重置了。感谢任何帮助。
我的代码:
to load-physician-file
file-open "Physician-File.csv"
while [not file-at-end?]
[
set csv file-read-line
set csv word csv ","
set fileList[]
while [not empty? csv]
[
let $x position "," csv
let $item substring csv 0 $x
carefully [set $item read-from-string $item] []
set fileList lput $item fileList
set csv substring csv ($x + 1) length csv
]
set State-abbrev item 0 fileList
if label-states
[
create-state-labels 1
[
set xcor (item 2 filelist - 1.6)
set ycor (item 1 fileList - 1.6)
set size 0
set label item 0 fileList
]
]
]
file-close
end
我强烈怀疑您遗漏了 file-close
或 file-close-all
。
也许与预期相反,clear-all
不会关闭文件,file-open
return 也不会关闭已打开文件的开头。