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

デコレータで関数に属性を付与

def note(**kw): def applier(func): __notes__ = getattr(func, '__notes__', None) if __notes__ is None: __notes__ = dict() setattr(func, '__notes__', __notes__) __notes__.update(kw) return func return applier @note(foo='this is add') @note(b…

cdefクラスとcpdefの挙動

Cythonでネイティブ実装のPythonクラスを作る。(Cython 0.24 で確認) # hoge.pyx from libc.stdio cimport printf from libcpp.string cimport string cdef class Hoge: cdef string name_ property name: def __get__(self): return self.name_.c_str().d…

.pyxはutf-8-sigにしてはいけない

# -*- coding: utf-8-sig -*- print(b'abc') print('abc') print('abc'.encode('utf-8-sig')) print('abc'.encode('utf-8')) env = Environment() env.Append( CPPPATH=['C:/Python34/include'], LIBPATH=['C:/Python34/libs'], ) env.Command('hoge.cpp', '…