科学の箱

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

RoboBrowserでUser Agentが原因ではねられているとき

RoboBrowserを利用していると通常のブラウザでリクエストした時とは異なりエラーがページが返ってくることが多い。 原因はいくつかあるがまず試したいのはUser-Agentの設定。 RoboBro …

no image

jupyterで目的のディレクトリから実行する方法

AnacondaをインストールするとJupyter Notebookを実行するショートカットが作成される。これをクリックするとJupyter Notebookは起動できるわけだが、残念ながら必要なファ …

no image

wordpress-xmlrpc

WordPressへPythonから投稿してみる。 まずは設定から。説明はこちらにある。 https://python-wordpress-xmlrpc.readthedocs.io/en/lates …

no image

複数のグラフを表示する方法

ここでは以下を説明する。 複数のグラフを表示する2つの方法 サブプロットのグラフを整形 複数のグラフを表示する 複数のグラフを表示するためには二通りの方法がある。 subplots()を使ってあらかじ …

no image

tensorflowをpipでインストールするときのオプション

tensorflow環境を構築するときにはpipを利用すると簡単である。pipの簡単な使い方としてはinstallオプションを指定すればよい。 pip install tensoflow しかしこのオ …

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

side bar top



アーカイブ

カテゴリー