2007-05-01から1ヶ月間の記事一覧

FizzBuzz問題

Pythonでの回答例で面白いものを見つけた。 Using FizzBuzz to Find Developers who Grok Coding for i in range(1,101):print"FizzBuzz"[i*i%3*4:8--i**4%5]or i ネタフリありがとう!<id:Voluntas

GUIDをちゃんと作る

COMコンポーネントを作るうえで避けられないGUID作成について。 (今回僕がGUID作成したいのは、COMコンポーネント用ではないんだけどね) よくあるGUID作成説明では、 import pythoncom print pythoncom.CreateGuid() という風にGUIDを作っていますが、これ、…

[pywin32]win32comでCOM serverを作ったとき、スクリプトを更新しても実行中イメージが更新されない問題

COM serverとしてあがっている間は、 元のPythonのスクリプトを更新しても実行イメージが変わらない。 The Python world tries to be polite [formerly offensive to another language] シェルエクステンションを作っているので、 explorer.exeを亡くならせ…

win32com.server.register.UseCommandLineのオプション一覧

win32com.server.register.UseCommandLineのオプション一覧 --unregister_info --unregister --quiet --debug debugを指定すると、PythonWinのTools->Trace Collector Debugging toolに出力が出る。 もしくは、C:\Python25\Lib\site-packages\win32\lib\win3…

ツールバーに入れたwxLabelの背景色が白くなってしまう。

xrcedでツールバーにラベルを入れてみたんだけど、 なぜか背景色が白くなってしまう @ windows環境。 誰かヘルプ!!!

ジェネレータ初めて使ってみた

SQLを実行して、その行を1つずつyieldする。 こんな使い方であっているかな。 def search_tags(self, tags): query = ' and '.join(['tag = ?' for w in tags]) self.cur.execute('SELECT id, fullpath, filetitle, ext, size, sha512, mtime FROM files WHE…

ファイル名をUnicode文字列に

os.walkなんかでpathを次々ととってくるときに、 path.decode(sys.getfilesystemencoding()) でファイル名をUnicode文字列に出来る。

数値をカンマ付き数字に変換(commify)

http://pleac.sourceforge.net/pleac_python/numbers.html から。 def commify(amount): amount = str(amount) firstcomma = len(amount)%3 or 3 # set to 3 if would make a leading comma first, rest = amount[:firstcomma], amount[firstcomma:] segment…

Windowsでのシェル拡張(シェルエクステンション)をPythonで実現

Python for Windows Extensionsが入っている環境だったら、 以下のファイルにサンプルがある。 C:\Python25\Lib\site-packages\win32comext\shell\demos\servers\context_menu.py

はじめまして。

グニャラくんのグニャグニャ備忘録@はてな で全文検索エンジンSennaの話とPythonの話とをまとめて書いていました。Pythonの(しかも細かい)話が多くなりそうなので分割。 というわけで、皆さんヨロシク。