gpt4 book ai didi

meson-build - 介子可以读取文件的内容吗

转载 作者:行者123 更新时间:2023-12-04 12:13:49 24 4
gpt4 key购买 nike

Meson 是否可以将文件内容读入数组或字符串?来自 here一个字符串可以拆分成一个数组,一个数组可以用foreach循环遍历。 ,但我一直无法找到从文件中获取数据的方法。

最佳答案

要完成@TingPing 的回答,我通常会这样做:

  files = run_command(
'cat', files('thefile.txt'),
).stdout().strip()
该方法也可以用于类似的事情:
  images = run_command('find',
meson.current_source_dir(),
'-type', 'f',
'-name', '*.png',
'-printf', '%f\n'
).stdout().strip().split('\n')
不要忘记使用 Meson 的文件引用可能有点不精确,因此您需要使用其中之一:
  • files('thefilename')
  • join_paths(meson.source_root(), meson.current_source_dir(), 'thefilename')

  • 编辑:对于更交叉兼容的解决方案,您可以使用 python 而不是 cat :
    files = run_command('python', '-c',
    '[print(line, end="") for line in open("{0}")]'.format(myfile)
    ).stdout().strip()

    关于meson-build - 介子可以读取文件的内容吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47174801/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com