科学の箱

科学・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

Python + Slack Bot – 3

さてリアルタイムでとりあえずうまくいったので、もう少し違うサンプルコードを試してみる。 参考にしたのはこちら。 https://www.fullstackpython.com/blog/build-f …

no image

jupyterで補完機能をつかう

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

no image

空の配列を生成

numpy.empty()を使うと要素が初期化されていない配列を生成できる。要素に入る値はその時により変わるので必ず初期化後には明示的に値を設定する必要がある。 numpy.empty print(n …

no image

pythonからoffice365 smtpを利用してメールを送信

Office365の設定はこちらにある。 PythonにおけるSMTPの利用はこちらにある。 下記はサンプルコード import smtplib from email.mime.text import …

no image

graphvizによる決定木の表示

graphvizの実行ファイルをインストール https://graphviz.gitlab.io/_pages/Download/Download_windows.html pythonにgraph …

2018年3月
月 火 水 木 金 土 日
« 2月   4月 »
 1234
567891011
12131415161718
19202122232425
262728293031  

side bar top



アーカイブ

カテゴリー