Python3関連のことを調べてみた2022年09月02日

Python3関連のことを調べてみた2022年09月02日

pythonでExcel操作を自動化する

openpyxlを使用して、seleniumで取得したデータをExcelへ入力する作業を自動化します。
csvに出力する等もあると思いますが、Excelはどこでも使っていると思うのでExcelを選びました。

## インストール

openpyxlを以下でインストールします

“`bash
$ pip install openpyxl
“`

インストール確認は以下です。

“`bash
$ pip list | grep openpyxl
openpyxl 3.0.10
“`

## ファイル読み込み

“`python
import openpyxl
wb = openpyxl.load_workbook(“読み込みたいファイル”)
“`

## シート読み込み

“`python
sheet = wb[“読み込みたいシート名”]
“`

## セル読み込み

“`python
value = sheet.cell(row=1, column=1).value
“`

A1セルを読み込む

row=行、column=列

“`python

元記事を表示

Windowsでpoetryが上手くインストールできない場合の対処

いつも通りPowerShellからpoetryを入れようとしたら入らなくなってた

“`PS
PS C:\Users\hoge> (Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python –
Retrieving Poetry metadata

This installer is deprecated, and cannot install Poetry 1.2.0a1 or newer.
Additionally, Poetry installations created by this installer cannot `self update` to 1.2.0a1 or later.
You s

元記事を表示

Python3 標準入力を辞書にする方法

先日、paizaラーニングのレベルアップ問題集で、連想配列の問題を解いていたときにでた疑問をまとめました。
https://paiza.jp/works/mondai/query_primer/query_primer__map_normal
(この練習問題の自分のコードも最後に載せてあります。)

### python3 で 標準入力を辞書の形にする方法

まず、リストを作成し、そこに要素を順に入れていきます。
“`Python
list_dic = []

for i in range(N):
list_dic.append(input().split())
“`
そして、“`dict()“`を使って辞書にします。

“`Python
dictionary = dict(list_dic)
“`

例:
標準入力
“`
1 Sin
2 Sakura
3 Kayo
4 Yui
“`

コード
“`Python
mylist=[]

for i in range(N):
mylist.append(input().split())

mydict=d

元記事を表示

PyScriptのすすめ

HTMLに直接Pythonが書ける画期的で革命的なライブラリのPyScriptについての情報を纏めます。

## 導入方法

ヘッダでJSライブラリをロードするだけです。

“`html