科学の箱

科学・IT・登山の話題

Python

automated the boring – day9

投稿日:2018年3月1日 更新日:

https://automatetheboringstuff.com/chapter17/

>>> from PIL import Image
>>> import os 
>>> os.chdir('c:\\temp\\pythonwork_01') 
>>> catIm = Image.open('zophie.png') 
>>> catIm.size (816, 1088) 
>>> width, height = catIm.size 
>>> width 816 
>>> height 1088 
>>> catIm.filename 'zophie.png' 
>>> catIm.format 'PNG' 
>>> catIm.format_description 'Portable network graphics' 
>>> catIm.save('copy.jpg') 

最後にsaveでjpgで保存している。オリジナルファイルの形式はpngだったがImageパッケージを利用するとファイル拡張子の変換も自動的に実施できる。

https://automatetheboringstuff.com/chapter18/

ようやくautomated the boringも最終チャプターまできた。このチャプターではマウスとキーボード操作について取り扱う。

まずはマウスからである。スクリプトを実行するとマウスは勝手に動く。正確にはスクリプトで指示されたとおりに動く


>>> import pyautogui
>>> pyautogui.size()
(1366, 768)
>>> width, height = pyautogui.size()
>>> for i in range(10):
... pyautogui.moveTo(100,100, duration=0.25)
... pyautogui.moveTo(200,100, duration=0.25)
... pyautogui.moveTo(200,200, duration=0.25)
... pyautogui.moveTo(100,200, duration=0.25)

 

とりあえずautomated the boringについてはここまでにしておく。pythonについて完全な初心者だととっつきずらい。ある程度文法が理解できているならばアプリケーションを作るための処理がコンパクトにまとまっているし、利用範囲がひろいパッケージが取り上げられているのでおすすめである。

メタ情報

inarticle



メタ情報

inarticle



-Python
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

グラフの軸を操作する

概要 ここでは以下の項目について取り扱う 軸にラベルを設定する ー xlabel, ylabel 軸の最小値、最大値を設定する ー xlim, ylim, xaxis 軸にメモリを設定する ー xti …

no image

jupyterで補完機能をつかう

まずはnbextentionsをインストール conda install -y -c conda-forge jupyter_contrib_nbextensions 次にnbextentionsタブ …

no image

配列同士の四則演算

ndarray同士で四則演算ができる。 この四則演算自体はnumpyにおけるbroadcastingと呼ばれる機能およびuniversal functionを利用して実現している。 numpyのbro …

no image

dataframeで条件を付けて要素を返す方法

前回の続きから。 dfは現在以下のようになっている。 W X Y Z A 2.706850 0.628133 0.907969 0.503826 B 0.651118 -0.319318 -0.848 …

no image

蟻本 P42 硬貨の問題

貪欲法の基本 その時点で最善の手を尽くす 尽くした結果を目的とする値に反映させる。 次善の手になるようにする。 1に戻る 硬貨の問題 A=int(input()) *C,=map(int,input( …

2018年3月
« 2月   4月 »
 1234
567891011
12131415161718
19202122232425
262728293031  

side bar top



アーカイブ

カテゴリー