Python
=================
Pythonは豊富な標準ライブラリが付属していることから“Batteries Included”と呼ばれている [#f1]_ .
GitHub
--------------
- Jaworski, M., & Ziadé, T. (2016). Expert Python Programming. Packt Publishing Ltd.
- https://github.com/PacktPublishing/Expert-Python-Programming-Third-Edition
- https://github.com/asciidwango/ExpertPython3_Source
- https://github.com/vinta/awesome-python
Style Guide
--------------
- `PEP 8 `_
- `Google `_
- `Plone `_
Docstring
^^^^^^^^
- `reStructuredText `_
.. code-block:: python
def func(arg1, arg2):
"""関数の概要
関数の詳細説明
:param arg1: arg1の説明
:type arg1: arg1の型
:param arg2: arg2の説明
:type arg2: arg2の型
:return: 返り値の説明
:rtype: 返り値の型
"""
- `Numpy `_
.. code-block:: python
def func(arg1, arg2):
"""関数の概要
関数の詳細説明
Parameters
----------
arg1: arg1の型
arg1の説明
arg2: arg2の型
arg2の説明
Returns
-------
返り値の型
返り値の説明
"""
- `Google `_
.. code-block:: python
def func(arg1, arg2):
"""関数の概要
関数の詳細説明
Args:
arg1 (arg1の型): arg1の説明
arg2 (arg2の型): arg2の説明
Returns:
返り値の型: 返り値の説明
"""
Code Formatter
^^^^^^^^
- `autopep8 `_
- `yapf `_
- `black `_: autopep8やyapfより制限が強い.
テスト
^^^^^^^^
- `unittest `_
- `nose `_
- `pytest `_
JupyterLab
--------------
Docker
^^^^^^^^
JupyterLabをDockerで使用する方法.
.. code-block:: c
docker run --rm -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes -v `pwd`:/home/jovyan/work --name jupyter jupyter/datascience-notebook
Sphinx
--------------
Docker
^^^^^^^^
SphinxをDockerで使用する方法.
.. code-block:: c
docker run --rm -v `pwd`:/docs sphinxdoc/sphinx --name sphinx make html
Scrapy
--------------
XML Path Language (XPath)
^^^^^^^^
- `scrapyでよく使うxpath, cssのセレクタ | Python Snippets `_
- `便利なXPathまとめ - ZOZO Technologies TECH BLOG `_
プログラムの高速化
--------------
- リスト内包表記 or mapを使う [#f2]_ [#f6]_
- list()ではなく[]を使う [#f4]_
- tupleを使う [#f5]_ [#f6]_
- f-stringを使う [#f3]_
- whileではなくforを使う [#f6]_
- 組み込み関数を使う
- numpyの関数を使って演算する
.. rubric:: Footnotes
.. [#f1] https://www.python.org/dev/peps/pep-0206/#id3
.. [#f2] https://stackoverflow.com/a/6407222
.. [#f3] https://www.scivision.dev/python-f-string-speed/
.. [#f4] https://stackoverflow.com/questions/30216000/why-is-faster-than-list
.. [#f5] https://stackoverflow.com/a/48936610
.. [#f6] https://qiita.com/shaka/items/f180ae4dc945dc7b9066