netlogo - 如何在 Netlogo 中打开同一个文件两次?(两个文件指针)
问题描述
我想打开同一个文件两次。在我之前的问题中,我试图检查文件是否包含空行。
我有一些 POC 代码来回答这个问题,但它需要打开同一个文件两次。
let who-file-name "world-health-field-surveillance.csv"
let who-file-name-dict csv:from-file who-file-name
let who-file-names sort [who] of names
let index 1 ;not 0, this removes the header in the csv
repeat length who-file-names [
file-open "world-health-field-surveillance.csv"
while [ not file-at-end? ][
let row csv:from-row file-read-line
if (not empty? row) [
ask names (item (index - 1) who-file-names) [
set label item 0 (item index who-file-name-dict)
该file-read-line
功能来自 Netlogo 的csv
扩展。
问题是 netlogo 的file-open
函数用于指定后续代码中引用的文件。
该行将let row csv:from-row file-read-line
推进文件指针并丢弃通常由行读入的行who-file-names
。
我应该怎么办?这似乎是 netlogo 的限制。但我也许能够以某种方式避免这个问题。
解决方案
推荐阅读
- html - 按列编辑表格
- php - if else 语句 js 嵌套在 php while 循环语句中 - 结果出现在循环之外/不显示
- python - ' TypeError: argument 1 must be pygame.Surface, not list ' : 不理解
- wpf - WPF 和 WinForm SerialPort 控制通过 RS232 的区别?
- math - 用 BCD 做 198-43
- javascript - 我如何知道输入的电子邮件是否对 jquery 有价值?
- python - 如何存储字符串的最后 n 个字符以连接到 Python 中的用户输入?
- java - 返回两个 int[][] 数组并且没有得到 java.lang.ArrayIndexOutOfBoundsException 的技术:-1 错误
- php - PHP生成带有条件的随机数数组
- javascript - 使用 Javascript(无 jquery)从 2 个 json 字符串追加数据 - 追加不是函数