2010-08-11 26 views
1

我嘗試了所有選項來在我的輸出文件中創建一個新行,但仍然得到一個txt文件,其中包含以前信息的所有內容。即使有這種supersimple代碼:NetLogo:輸出文件中的換行符?沒那麼簡單。

全局[文件]

to setup clear-all 
    set file "results\\GA1.txt" if is-string? file 
    [while [file-exists? file] 
     [set file replace-item (length file - 5) file "11" ] 
     file-open file] end 

to go tick write-to-file end 

to write-to-file file-print (word ticks) FILE-TYPE "\n" file-write 1 file-print (word " " 2 ";") file-write 1 file-print (word " " 2 ";")  file-print "" ;; blank line end 

我不明白的空白行或換行。我在NetLogo 4.1中工作。有人知道可能是什麼問題嗎?

回答

1

您忘記關閉文件file-close或強制它將數據寫入磁盤,並使用file-flush

當您執行file-write時,數據不會立即寫入磁盤。它被放置在緩衝區中。當緩衝區足夠大時,數據被寫入磁盤。您可以使用file-flushfile-close命令強制netlogo將數據寫入文件。

3

回答在http://netlogo-users.18673.x6.nabble.com/Adding-a-new-line-when-outputting-data-tp4870905p4870909.html,我寫道:

你在Windows和使用記事本查看你的文件嗎?其他Windows程序幾乎每個 這些天都瞭解Unix式的換行符, 但是記事本沒有。

+0

雅虎阻止用戶沒有一個帳戶,最好在這裏補充答案直接 – tong 2014-07-15 15:42:06

+0

@tong : 好點子。替換爲同一帖子的Nabble網址 – 2014-07-15 18:37:45

1

該參考文獻建議使用更好的編輯器。但是有一種方法可以使記事本工作。

如果您將字符串「\ r \ n」添加到您的數據(使用文件類型或其他),它可以使用記事本。

記事本使用較舊的回車符(「\ r」)/新行(「\ n」)格式。 Unix系統只使用新行。

0

試試這個,這對我的作品

file-open "locations.txt" 
    ask turtles 
    [file-print xcor] 
file-close 

,如果你想要更多的休息,然後用這個

file-open "locations.txt" 
    ask turtles 
    [file-print xcor file-print "\n"] 
file-close 
相關問題