LoginSignup
1
2

More than 3 years have passed since last update.

Pythonで、ファイルの書き出しと出力

Last updated at Posted at 2020-09-26

Pythonで、ファイルの操作をする。

簡単ですが、ファイルの操作のコードです。
ディレクトリーファイルを作って、フロントエンドとバックエンドのファイルを管理する認識だと思います。
合ってますでしょうか?
実行環境は、Pycharm
Macbook pro 13 2020を使用しています。

実行したソースコード


import string

with open('directly_folder/sample.html') as f: #sample.txtでも可能
    t = string.Template(f.read())
contents = t.substitute(name='your nickname',contents='favorite phase?')
print(contents)

以下のコードがファイルの場所と内容を示すコードです。

py -m pip openpyxl //windowsの場合 コマンドプロンプト
pip openpyxl // ターミナルでインストールされているか確認する
pip openpyxl--upgrade pip// アップデートする

import os
import sys
import openpyxl
wb = openpyxl.load_workbook(path)
ws = wb["Sheet1"]
ws["A1"].value = "X"
wb.save(path)

エラーへの対処がすこしわかりました。

ファイルは、エクセルシートへの出力でしょうか。
Jupyternotebookでしたら、可能です。
https://gammasoft.jp/support/pip-install-error/
参考リンクです。

1
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2