首页 > 解决方案 > 如何在 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 的限制。但我也许能够以某种方式避免这个问题。

标签: netlogo

解决方案


推荐阅读