TopCoderに登録してみる。
http://www.topcoder.com/
英語を読むのにも一苦労。全く勝てる気がしないが・・・
Pylint コンフィグファイル
eclipse で Pylint の設定をするとき、「—indent-string="○○"」(※○は半角スペース)と設定しても、Pylint 実行時にはスペースの数が2個ではなく1個になってしまう。
そこで、コンフィグファイルを作成しそれを編集して読み込ませることにした。
以下のようなパス検索が行われているようだ。
・カレントディレクトリ/pylintrc
・環境変数「PYLINTRC」で定義されているパス
・ホームディレクトリ/.pylintrc
・/etc/pylintrc
・config.py(76行目~)
# location of the configuration file ##########################################
def find_pylintrc():
    """search the pylint rc file and return its path if it find it, else None
    """
    # is there a pylint rc file in the current directory ?
    if exists('pylintrc'):
        return abspath('pylintrc')
    if isfile('__init__.py'):
        curdir = abspath(os.getcwd())
        while isfile(join(curdir, '__init__.py')):
            curdir = abspath(join(curdir, '..'))
            if isfile(join(curdir, 'pylintrc')):
                return join(curdir, 'pylintrc')
    if 'PYLINTRC' in os.environ and exists(os.environ['PYLINTRC']):
        pylintrc = os.environ['PYLINTRC']
    else:
        user_home = expanduser('~')
        if user_home == '~' or user_home == '/root':
            pylintrc = ".pylintrc"
        else:
            pylintrc = join(user_home, '.pylintrc')
    if not isfile(pylintrc):
        if isfile('/etc/pylintrc'):
            pylintrc = '/etc/pylintrc'
        else:
            pylintrc = None
    return pylintrc
PYLINTRC = find_pylintrc()
ENV_HELP = '''
The following environment variables are used :                                 
    * PYLINTHOME                                                               
    path to the directory where data of persistent run will be stored. If not
found, it defaults to ~/.pylint.d/ or .pylint.d (in the current working
directory).
    * PYLINTRC                                                                 
    path to the configuration file. If not found, it will use the first        
existent file in ~/.pylintrc, /etc/pylintrc.
''' % globals()
コンフィグファイルの作成には、「pylint --generate-rcfile」を行えばよい。
たとえば、Windowsマシンで Python が Eドライブにある場合、このように作成する。
   1: e:\>mkdir \etc   2:     3: e:\>pylint --generate-rcfile > \etc\pylintrc   4:     5: e:\>Solaris: 稼働中プロセスの umask 値を取得する
mdbで実現可能。
# mdb –k
> ::pgrep プロセス名
> アドレス::print –t proc_t p_user.u_cmask
プロセスIDから「pid2proc」を使って検索してもよい。
> 0tプロセスID::pid2proc | ::print –t proc_t p_user.u_cmask
proc_t 全部を出力し、OSコマンドの「grep」で抽出することもできる。
> アドレス::print –t proc_t ! grep u_cmask
これらで出力されるのは、いずれも16進数の値。
「umask」などで表示される8進数の形式に直すと、下記の例だと「022」となる。
(0x12 <16進数> = 022 <8進数>)
   1: # mdb -k   2: Loading modules: [ unix krtld genunix specfs dtrace cpu.generic uppc pcplusmp zfs mpt ip hook neti sctp arp usba uhci fctl nca lofs cpc random crypto fcip logindmux ptm ufs sppp nfs ]3: > ::pgrep sshd
   4: S    PID   PPID   PGID    SID    UID      FLAGS     ADDR NAME   5: R    512      1    512    512      0 0x42000000 dff67140 sshd6: > dff67140::print -t proc_t p_user.u_cmask
   7: mode_t p_user.u_cmask = 0x128: > 0t512::pid2proc | ::print -t proc_t p_user.u_cmask
   9: mode_t p_user.u_cmask = 0x1210: > 0t512::pid2proc | ::print -t proc_t ! grep u_cmask
  11:         mode_t u_cmask = 0x1212: > $q
  13:    14: #Python版mogmail
・mogmail.py
1: # Copyright (c) 2011 Mog Project. All rights reserved.
   2: import poplib   3: import email   4: from email.header import make_header   5: from email.header import decode_header   6: from email.utils import parsedate_tz   7: from email.utils import mktime_tz   8: import time   9:  10: POP3_SERVER = 'POP3-Server'
  11: POP3_PORT = 11012: POP3_USERNAME = 'UserName'
13: POP3_PASSWORD = 'Password'
  14: LIST_COUNT = 5  15:    16: def main():  17:   pop3 = poplib.POP3(POP3_SERVER, POP3_PORT)  18:   pop3.apop(POP3_USERNAME, POP3_PASSWORD)  19:  20: for p in pop3.list()[1][:-1 - LIST_COUNT:-1]:
21: msg_no = p.split(' ')[0]
22: msg = email.message_from_string('\n'.join(pop3.retr(msg_no)[1]))
  23:    24:     f = lambda str: unicode(make_header(decode_header(msg[str])))  25:    26:     try:27: print time.strftime('[%m/%d %H:%M]',
28: time.localtime(mktime_tz(parsedate_tz(f('Date'))))),
29: print '%s\n %s' % (
30: f('From').replace('"', ''), f('Subject'))
  31:     except:32: print '*** Error ***'
  33:  34: if __name__ == '__main__':
  35:   main()POP3サーバ名および認証情報はハードコーディング。
[2011/10/12]
改良版はこちら:
http://mogproject.blogspot.com/2011/10/mogmail-with-python-version-11.html
Python版POP3クライアント
O'REILLY『初めてのPython 第3版』をおよそ半分くらい読んだところ。
以前C++で書いたPOP3メールのヘッダ情報を出力するプログラムを、Pythonで作ってみる。
・mogmail.py(作成途中)
   1: import poplib, email   2:  3: pop3 = poplib.POP3('POP3-Server')
4: pop3.apop('UserName', 'Password')
   5:  6: for p in pop3.list()[1][:-6:-1]:
7: msg_no = p.split(' ')[0]
8: msg = email.message_from_string('\n'.join(pop3.retr(msg_no)[1]))
   9:    10:   f = lambda str: unicode(  11:       email.Header.make_header(email.Header.decode_header(msg[str])))  12:  13: try:
14: print '%s\n %s' % (f('From'), f('Subject'))
  15:   except: pass嫉妬する程美しい言語だ!(コードが汚いのはご勘弁・・・)
ただ、たまにBase64のデコードに失敗するのはなぜだろう。
Pythonは、今世紀のプログラミング言語の最高傑作たりえるか?
(2011/4/24)改良版 ⇒ http://mogproject.blogspot.com/2011/04/pythonmogmail.html
Windows: 左Alt+Shiftでキーボード配列が変わる
Windows Vistaマシンで Eclipseを使ってたら、突然キーボード入力が英語キーボード配列になってしまった。
OS側のショートカット(左Alt+Shift)で入力言語が切り替わったのが原因。
英語キーボードを使わないなら、コントロールパネルから「地域と言語のオプション」
-「キーボードと言語」-「テキスト サービスと入力言語」-「詳細なキー設定」で
入力言語のホット キーを無効にしておけば良い。
PyDev with Eclipse のセットアップ
Pythonの勉強は始めたばかりだが、これは面白い。
現在最も完成されたスクリプト言語であり、(日本では時間がかかるだろうが)今後の主流となっていくのであろう。
環境を整える。
IDEランキング
http://stackoverflow.com/questions/81584/what-ide-to-use-for-python
Eclipseのダウンロード・セットアップ
今回は Eclipse Classic 3.6.2 を導入
http://www.eclipse.org/downloads/
PyDevのインストール・セットアップ手順
http://www.brainchild.co.jp/blog/develop/2010/08/python-eclipse1.html
Google Python スタイルガイド
本家
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html
stdint.h: ビルドエラー C4005
VC++ 2010 で <stdint.h> をインクルードすると警告が出る。
http://connect.microsoft.com/VisualStudio/feedback/details/621653/including-stdint-after-intsafe-generates-warnings
回避方法
1: #ifdef _MSC_VER // This check can be removed if you only build for Windows.
2: #pragma warning (push)
3: #pragma warning (disable : 4005)
4: #include <intsafe.h>
5: #include <stdint.h>
6: #pragma warning (pop)
7: #endif // _MSC_VER
pythonのtelnetlibを使うと、TCP通信を細かくコントロールでき、
TeraTermマクロのようなことも可能となる。
http://www.python.jp/doc/2.4/lib/module-telnetlib.html
開発・メンテの効率化のため、棋譜などのファイルI/O部分、およびN/W通信部分は
全て Pythonで書き直すことに決定。
コア部分はC++。コンポーネント統合(?)についてはこれから勉強。
将棋プログラムの話。