コンテンツにスキップ

Overview

IDE

  • PyCharm
  • PyScripter
  • PTVS (Python Tools for Visual Studio)

Style guide

守らなくても良いけど、理由が無いなら守っておく。

Code style checker

  • pycodestyle
  • flake8 - PEP8以外にいくつかスタイルガイドが追加されているチェッカー
  • hacking - OpenStack projectで使われているスタイルガイドラインチェッカー
  • ~~pep8~~ obsolated. pycodestypeに改名。

virtualenv/venv

どうやらDjangoによればvenvは1か所のディレクトリにまとめて置いておくのが良いらしい。

https://docs.djangoproject.com/ja/2.0/intro/contributing/#getting-a-copy-of-django-s-development-version

と言うわけで、今後はそうすることにした。

Windowsの場合

Powershellでこのようにする。

> mkdir ~\.virtualenvs
> python -m venv ~\.virtualenvs\project
> .\~\.virtualenvs\project\Scripts\activate.ps1

以下のエラーが出る場合はps1スクリプトを叩けるように、事前に Set-ExecutionPolicy RemoteSigned -Scope Process -force を叩いておく。

    + CategoryInfo          : セキュリティ エラー: (: ) []、PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Testing

BDD framework

  • pytest-bdd
  • behave

pytest

Packaging

  • setup.py
  • requirements.txt

インストール

  • setup.pyを使う(パッケージングされたファイル郡に含まれていれば)
    python setup.py install
    
  • easy_install
    apt-get install python-setuptools
    
    • proxyは環境変数が使える
      export http_proxy=http://example.com:8080
      export https_proxy=http://example.com:8080
      
  • pip
    • apt-get install python-pip
      • バージョン低すぎて、uninstall出来ないとかなるので、easy_install推奨。
      • easy_install pip
    • proxy: pip install <package-name> --proxy=http://example.com:8080

Utilities

Parser

状態遷移

非同期ジョブ

Graph

  • matplotlib
  • Bokeh
  • Highstock

matplotlib

公式サイト: http://matplotlib.sourceforge.net/index.html

  • 数値計算、グラフ描画の助けに。
  • ヒストグラムのbinsはmax(value)で決定してもいいものだろうか。デフォルト10って何なんだろう。
    • ヒストグラムに突っ込んだ値を何分割するかを決めるから、最大値でいいんじゃね、って思ってる。
  • py2exeでexe化するときは少し癖があるよう。
  • インストール
    • win用のインストーラ使ってしまったので...
    • windows 7でeasy_installしたらエラー出たし...

pypcap

memo

RFC5952

文字列とバイナリ表現の相互変換用のスクリプト。

こんな感じで使う。

>>> import rfc5952
>>> binary = '\x20\x01\x0d\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
>>> rfc5952.inet6_ntoa(binary)
'2001:db8::1'
>>> string = "2001:db8:1f1f:90::82"
>>> rfc5952.inet6_aton(string)
' \x01\r\xb8\x1f\x1f\x00\x90\x00\x00\x00\x00\x00\x00\x00\x82'

~~Bitbucketで公開: https://bitbucket.org/ainoniwa/rfc5952/src/dcb12192d35f730d843f2922e0d0b75f702d2092/rfc5952.py~~

GUI

PySide

PythonからQtを扱うためのバインディング。PyQt4のライセンスがGPLだったので、LGPLなPySideを使うことにする

wxPython

開発環境

  • Windows
  • 独立環境
    • virtualenv
      • pip install virtualenv
      • 使う時は、以下をセットで。
        $ virtualenv project-name --no-site-packages
        $ source ./project-name/bin/activate
        $ # --- ホスト名に(project-name)が付いたらOK
        $ deactivate
        $ # --- これで抜ける
        

最終更新日: 2021-05-22 13:37:13