Skip to main content

ファイル書き込み

Python

py
with open(fname, 'w') as f:
f.write(s) # 改行は入らない
  • f.write(line)
  • f.writelines(lines)

どちらも改行は入れてくれないので、自分で入れる。

py
f.writelines([line + '\n' in lines])
f.writelines('\n'.join(lines) + '\n')

とか?

PowerShell

powershell
Out-File -LiteralPath o.txt
powershell
Out-File -LiteralPath o.txt -Append