みんなのIoT/みんなのPythonの著者。二子玉近く160平米の庭付き一戸建てに嫁/息子/娘/わんこと暮らしてます。月間1000万PV/150万UUのWebサービス運営中。 免責事項 プライバシーポリシー 以前pudbというCUIベースのソースコードデバッガを紹介した。コンソール環境で利用できてなかなかファンシーなのだが,デバッガをいちいち立ち上げる必要があるので少々面倒だ。今回はより手軽にCUIベースのデバッガを起動する方法を紹介する。 方法は簡単。debugというパッケージを「pip debug」などでインストール,デバッグを開始したい場所に「import debug」とするだけで,プログラムのその位置でシンタックスカラーリングの効いたファンシーなデバッガが立ち上がる。 「n」を押して実行を進めたり,print文を使って実行中の変数の中身を表示したりできる。実行中のプログラムも表示し
Pythonの標準ライブラリにはプロファイラがあるが、これは deterministic profiler という種類のプロファイラだ。関数が呼び出されたときと関数から抜けるときに登録したコールバック関数を呼び出す仕組みが用意されており、そのコールバック関数で時間を測ることで、各関数の実行時間を測ることができる。 このプロファイラは、短時間の実行で正確な時間を計測できるので、マイクロプロファイリングには適している。しかし、プロファイルを実行するとプログラムの実行速度がかなり低下してしまうという問題もある。 deterministic profiler と別の方式に、 statistical profiler というものがある。 これは、何らかの周期でプログラムのどこを実行しているのかをサンプリングするものだ。実行時間の長い関数ほど何度もサンプリングされるので、サンプル数が実行時間に比例する
移転しました http://please-sleep.cou929.nu/20110525.html
Flash製アプリの試験用のアクセスパターンを作りたくて gevent を使って簡単なproxy serverを作った。 localhostの8000版で立ち上がるので、FoxyProxy などで、特定のドメインに対する proxy として登録してやると、リクエストを再現するのに必要なデータをmsgpackフォーマットで保存していく。 from gevent.pywsgi import WSGIServer from gevent import monkey from msgpack import packs import httplib def handler(environ, start_response): host = environ['HTTP_HOST'] method = environ['REQUEST_METHOD'] body = environ['wsgi.input
Sphinx使っているのだけどファイルを更新するたびにmake htmlと打って確認するのがめんどくさい。linuxだったらpyinotifyがあるんだけど、macbookでは使えない。 簡易コマンド書いた。 #!/usr/bin/env python import os from time import sleep, strftime, localtime import sys import commands filename = sys.argv[1] mycommand = sys.argv[2] def get_mtime(): return os.stat(filename).st_mtime mtime = get_mtime() while 1: sleep(1) new_mtime = get_mtime() if mtime != new_mtime: mtime = n
Installation pip install chardet Quick Start import chardet chardet.detect(b"Python is a great programming language for beginners and experts alike.") # {'encoding': 'ascii', 'confidence': 1.0, 'language': 'en', 'mime_type': 'text/plain'} # UTF-8 English with accented characters chardet.detect("The naïve approach doesn't always work in complex systems.".encode("utf-8")) # {'encoding': 'utf-8', 'co
Python Basics Python - Home Python - Overview Python - History Python - Features Python vs C++ Python - Hello World Program Python - Application Areas Python - Interpreter Python - Environment Setup Python - Virtual Environment Python - Basic Syntax Python - Variables Python - Data Types Python - Type Casting Python - Unicode System Python - Literals Python - Operators Python - Arithmetic Operator
みんなのIoT/みんなのPythonの著者。二子玉近く160平米の庭付き一戸建てに嫁/息子/娘/わんこと暮らしてます。月間1000万PV/150万UUのWebサービス運営中。 免責事項 プライバシーポリシー pudbは,CUI環境(つまりシェル)で動くGUIライクなデバッガ。Pythonには標準でpdbというデバッガがついてくるけど,コマンドラインベースでちょっと使い方が面倒だよね。pudbはpdbよりノリがいい。まあスクリーンショットを見てもらうのが早いかな。 CUIベースでGUIっぽいことをするというのは,レトロなノリだよなあ。でもCUIベースならシェルが動く環境ならどこでも動く,という利点もある。ローカルのPythonでもssh越しのPythonでも,シェル上なら同じように動くというのは嬉しい。 インストールは簡単。いつものごとくeasy_installを使って「$ easy_ins
こんばんは、最近なんだかバテ気味の若手ブログ初登場、nakazawa-kです。 よろしくお願いします。 どうやらIRCボットのコンテストをやるらしいと聞いて息巻き、大急ぎでざくっと実装してから実に2ヶ月ほど寝かせてしまったボットを投下してみます。 最初のお題が出た瞬間に思いついたのが「Pythonボット」でした。『Pythonで書かれた』という意味ではなく『Pythonを実行してくれる』ということです。 (nakazawa-k) >>>print "hello!" (bot) hello! こういう風にIRCがPythonコードであふれたら素敵だと思いませんか!? 私は思います。作りましょう。これで機能が決まりました。 次は超重要、名前です。 みなさんパイソンといえば何を思い浮かべるでしょう。 ニシキヘビ? いえいえパイソンといえばモンティ・パイソンです。テリー・ギリアムです。 Pyt
PEP 8 – Style Guide for Python Code PEP 8 – Style Guide for Python Code Author: Guido van Rossum <guido at python.org>, Barry Warsaw <barry at python.org>, Alyssa Coghlan <ncoghlan at gmail.com> Status: Active Type: Process Created: 05-Jul-2001 Post-History: 05-Jul-2001, 01-Aug-2013 Table of Contents Introduction A Foolish Consistency is the Hobgoblin of Little Minds Code Lay-out Indentation Tabs
pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls, but it has support for more complex actions like getting text data. Supported technologies under the hood: Win32 API (backend="win32"; used by default), MS UI Automation (backend="uia"). User input emulation modules mouse and
overlasting.net 2019 Copyright. All Rights Reserved. The Sponsored Listings displayed above are served automatically by a third party. Neither the service provider nor the domain owner maintain any relationship with the advertisers. In case of trademark issues please contact the domain owner directly (contact information can be found in whois). Privacy Policy
multiprocessingモジュール multiprocessingモジュールは、Python2系列では2.6以降、3系列では3.0以降に標準となったモジュールです。このモジュールはthreadingモジュールに似たAPIでプロセス間通信などの機能を提供します。このモジュールにより、GILの問題を回避することができ、複数のCPUやCPUコアの性能を生かすことができます。また、このモジュールはローカルのみならず、リモートでのプロセス間通信も行うことが可能で、簡単に分散処理などを実装することができます。 まず、GIL(Global Interpreter Lock)とはPythonのインタプリタ上で一度に1つのスレッドだけが動作するよう保証するためのロックです。このロックによって、同時に同じメモリにアクセスするスレッドが存在しないことを保証します。 しかしながら、このロックによって、一度に
1.1 ディレクトリ内の全てのファイルをリストする import sys, os if len(sys.argv) != 2: sys.exit("a single argument (the directory name) is required") try: filenames = os.listdir(sys.argv[1]) except OSError: sys.exit("can't open {0}".format(sys.argv[1])) for filename in filenames: print filename sys.exit(0) Pythonでは、opendir()/readdir()/closedir()を個別に呼び出す必要はなく、os.listdir()だけでファイル一覧を取得することができる。ただし、readdir()と違って、os.listdir(
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く