在 Julia 中创建文本文件

Geo*_*ery 3 julia

我有一根绳子

a = """
---
title: Just a test
author: Me
date: 2022-01-03
---

# Test Header 
Some text.
"""
Run Code Online (Sandbox Code Playgroud)

我想从中创建一个文件foobar.jmd。这样做的最佳方法是什么?

vas*_*sja 8

fname = "foobar.jmd"
dirpath = "/tmp"
fpath = joinpath(dirpath, fname)

open(fpath, "w") do file
    write(file, a)
end
Run Code Online (Sandbox Code Playgroud)

更多示例,例如此处https://en.wikibooks.org/wiki/Introducing_Julia/Working_with_text_files

  • write(fpath, a) 是一个很好且等效的简写。 (4认同)