オブジェクト指向プログラミング+multiprocessing.Poolでの並列処理でハマりました。 クラスの中でPoolライクな文法で並列演算を行なうことのできるMyPoolを自作したのでその紹介です。 Pythonでの並列処理について Pythonにはver2.6以降からmultiprocessingという便利なものがあります。 これのPoolという機能を使うと、 test.py # -*- coding: utf-8 -*- from multiprocessing import Pool def fuga(x): # 並列実行したい関数 return x*x def hoge(): p = Pool(8) # 8スレッドで実行 print p.map(fuga, range(10)) # fugaに0,1,..のそれぞれを与えて並列演算 if __name__ == "__main
Technical blog on the Python programming language, in a pure Frenglish style. Main topics are Python and Mozilla – This blog does not engage my employer Python is gaining a lot of traction in many Mozilla projects. From the SUMO and AMO websites, to Socorro and the next-gen Firefox Sync server. I can fairly say that it becomes a mainstream language for building server-side software in our eco-syst
はてなダイアリーのデータを定期的にバックアップする - 素人がプログラミングを勉強していたブログで紹介されているツールが便利そうだったので、Pythonに移植してみました。 まずは素直にMechanizeっぽいコードに。 #! /usr/bin/env python # -*- coding: utf-8 -*- from datetime import datetime import yaml, os, time, mechanize CONFIG = yaml.load(open('config.yaml')) USERNAME = CONFIG['username'] PASSWORD = CONFIG['password'] DIR = CONFIG['backupdir'] if not os.path.exists(DIR): os.mkdir(DIR) client = me
エキスパートPythonプログラミング読書会04 : ATND に参加してきました。 今回は第3章のクラスのお話です。私は小規模開発や普通のアプリケーション開発にしか携わったことがないのですが、wikipedia:オブジェクト指向プログラミング を行うところの、本質的な良さや恩恵を実体験をもってはあまり理解できていません。とはいえ、そういった仕組みを理解して、より良いアプリケーション開発に有用なら使ってみたいですよね。そんな風に考えながら聞いていました。読書会で @shimizukawa が解説していた内容の中で聞いていて私が印象に残ったことを整理してみます。 特殊メソッドを定義することで構文の振る舞いを簡単に実装できる 組み込み型の str を継承した mystr を定義して文字列の連結と比較を細工してみましょう。以下のサンプルでは、特殊メソッド __add__() で文字列の連結処理を
How to test your __eq__ / __ne__ / __cmp__ In Python, a common mistake is to implement __eq__ on your object without also implementing __ne__. Even worse, your unit tests will often hide the error because the default object-identity __ne__ will probably satisfy your assertions. If you’ve implemented __eq__ and __ne__, you might still have a mistake if the superclass has a __cmp__: Python’s cmp wil
About Us We are a large online store of domain names with history and parameters (DR - domain rating, DA - domain authority, backlinks, age, etc.). If you are launching a new project online, then you have come to the right place! The store is updated daily (if there are new domains in our database). Don't Lose That Domain! Secure your online future with SanJosePayday.Loans! We offer quick cash adv
A friend of mine and I like to show off to each other little Emacs tips and tricks we learn. Today, he introduced to me the very cool AutoComplete.el package. AutoComplete.el is intriguing to me because, unlike ropemacs mode which I've blogged about before, the completions AutoComplete.el provides are inline with your code in a dropdown box instead of in a seperate window (windows in Emacs are wha
動機 開発にはずーっとEmacsを使っているけれど、最近M-/の補完を不便に感じるようになったので、補完窓が出るような拡張を入れてみたくなった。 方法 下記サイトの方法をそのまま実行しただけです。 EnigmaCurry まずMercurialをインストールして、rope, ropemacs, ropemodeをDLし、ropeとropemacsをインストール。 $ sudo ports install mercurial ---> Installing bzip2 @1.0.5_1 ---> Installing py25-bz2 @2.5.4_0 ---> Installing mercurial @1.1.2_0 $ mkdir ~/pkg/rope && cd ~/pkg/rope $ hg clone http://bitbucket.org/agr/rope/ $ hg clo
上記の質問がハッカーニュースに上った: http://news.ycombinator.com/item?id=1803351 さすがHNだけあって、PGはもとよりDaniel WeinrebやPeter Norvigを含む豪華絢爛のキャストで議論が行われた。 長いけどLispやダイナミック言語一般に興味のある方には一読の価値あり。以下、面白いところを数ヶ所掻い摘まむ。 古株のLisper達(例えばPeter Norvig)がPythonにくら替えしているようだけど、現時点でLisp VS Pythonについてどう思います? 確かに最近そういう傾向がある。MITでもSICPが無くなってPythonでロボットを駆るクラスに変ったらしい。 Peter Norvigです。Pythonに行き付いたのはそれがより優れ、受け入れられ、実用的なLispであるからではなく、それがより優れたpseudoco
あなたにとって重要なトピックや同僚の最新情報を入手しましょう最新の洞察とトレンドに関する最新情報を即座に受け取りましょう。 継続的な学習のために、無料のリソースに手軽にアクセスしましょうミニブック、トランスクリプト付き動画、およびトレーニング教材。 記事を保存して、いつでも読むことができます記事をブックマークして、準備ができたらいつでも読めます。
Pythonバージョン 2.5 or 2.6を使う。 3.xはまだ時期尚早というか、DjangoやGoogle App Engineが対応していないので事実上選択肢にならない (DjangoとGoogle App Engineが対応したら移行が加速すると思います)。 ちなみに、RedHat LinuxにはPython 2.4がプリインストールされていますが、 SQLiteが動かないなど開発作業を行うにあたってはちょっと厳しい。 ソースコンパイル 、 EPEL からyumで拾う、aptitude install python2.5するなどなど、お好きな方法でインストールしてください。 MacOSXならMacPortsが便利です。 パッケージ管理 とりあえずsetuptoolsとpip入れましょう。 setuptools pip setuptools入れ方: wget http://peak.
前回からの続きです FirePython の初期設定?を見てみる http://firelogger.binaryage.com/#usage にある、Real world examples を参考にするも、エラーが出る。なんか jsonpickle が必要らしい。Google Code で公開しているので、そこから egg を取ってきて zip にリネームして展開。不要なファイルを削除して最上位ディレクトリ に置く。 そしてゴニョゴニョいじるが、相変わらずエラーは収まらない。しかしココで分かった事がひとつ。単独でログ出力をしているわけではなく、Python 2.3 以降で追加されたロギング機能に入り込んでいるみたいだ。だから、詳しい使い方が無かったのか…。アプリケーションの初期化部分で準備するだけで良いって事だ。あと、middleware として動いているというのも分かった。 とわかった
こんにちは!DQNです! python2.6はいろいろ変更点が入って便利になります。 python2.6からはselectモジュールにepoll、kqueueが追加されます。 DQNが思うに変更点の目玉のひとつかだけど余り触れられてないと思うので書いて見る。 ほぼCのラッパーなので使い方もほぼ同じです。 Macなのでkqueueのサンプルです from select import * kq = kqueue() file = open('test.txt', 'r') ke = kevent(file.fileno(), KQ_FILTER_VNODE,\ KQ_EV_ADD|KQ_EV_ENABLE|KQ_EV_ONESHOT,\ KQ_NOTE_WRITE|KQ_NOTE_DELETE, 0, 0) active = True while active: events = kq.con
py-kqueue http://pypi.python.org/pypi/py-kqueue/kqueueバインディング。同じものにPyKQueueがあるが、py-kqueueの方がPython2.2以降に対応ということでC拡張としての作りがモダンで、よりオブジェクト指向のPythonらしいAPIを提供している。インストールは、 $ sudo easy_install py-kqueue でもできるのかもしれないが、ソースを見てみたかったのでzipを解凍してsetup.pyを自分でたたいた。 $ curl -O http://pypi.python.org/packages/source/p/py-kqueue/py-kqueue-2.0.zip $ unzip py-kqueue-2.0 $ cd py-kqueue-2.0 $ sudo python setup.py install
みんなのIoT/みんなのPythonの著者。二子玉近く160平米の庭付き一戸建てに嫁/息子/娘/わんこと暮らしてます。月間1000万PV/150万UUのWebサービス運営中。 免責事項 プライバシーポリシー 元記事 : Farewell To Microsoft IronPythonを開発していたJim Hugnin氏がMicrosoftを去り,Googleに行くようです。 彼はJava VM上でPythonの実行環境を実装したJythonの作者でもあります。Microsoftで氏は,IronPythonだけでなく,.NET上で軽量言語を走らせるためのDynamic Language Runtime (DLR)も作っていました。IronRubyなどもDLRの恩恵があって実装されています。 また,ほぼ同時に,MicrosoftがIronPython,IronRubyへの直接投資を打ち切ること
http://d.hatena.ne.jp/jYoshiori/20090121/1232526865 autotestか!っていうコードだけど。 Linuxならpyinotifyを使えばいいんじゃないかな。 from pyinotify import WatchManager, Notifier, IN_MODIFY, ProcessEvent wm = WatchManager() mask = IN_MODIFY class PTmp(ProcessEvent): def process_IN_MODIFY(self, event): print "m: %s" % event.name notifier = Notifier(wm, PTmp()) wdd = wm.add_watch('../', mask, rec=True) notifier.loop() directory
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く