Python

printの型ってなに? on Python

Ubuntu 10.10 Python 2.6 __builtins__の型を調べてたら、printだけSyntaxErrorになる なんで? print type(Exception) # <type 'type'> print type(False) # <type 'bool'> print type(open) # <type 'builtin_function_or_method'> print type(print) # SyntaxError: invalid syntax</type></type></type>

継承 on Python

Ubuntu 10.10 Python 2.6 ■プログラム(TestInheritance.py) #-------------------- # 継承 #-------------------- # 親クラスその1 class Oya_A(object): val = "AAAAA" def __init__(self): print "oya_A:init" def oyako(self): print "oya :" + self.val…

クラス on Python

Ubuntu 10.10 Python 2.6.6 ■プログラム(TestClass.py) #! /usr/bin/env python # coding:utf-8 # クラスを定義する class SampleClass(object): ''' ドキュメンテーション。クラスの説明。 ''' # インスタンス変数 moji = "aiueo" # 初期化処理 def __init_…

例外処理 on Python

Ubuntu 10.10 Python 2.6 ■プログラム(TestError.py) #! /usr/bin/env python # coding:utf-8 class TestError(object): ''' 例外処理 ''' def __init__(self): ''' 変数初期化 ''' self.nums = [1, 2, 3, 4, 5] self.strs = ["a", "b", "c", "d", "e"] def …

ログの出力 on Python

Ubuntu 10.10 Python 2.6 ログの環境設定ファイルの取得が面倒でなければ、printでデバッグするよりいいかも。 ■環境設定ファイル(log.conf) [loggers] keys=root,app [handlers] keys=stream [formatters] keys=form [logger_root] level=NOTSET handlers=s…

ImportError: cannot import name

Python 2.7 どツボった。 ImportError: cannot import name■事象 以下のようなモジュール構造で、互いにモジュールを呼び合う場合に発生。 view\ __init__.py form1.py form2.py・form1.py from veiw.fom2 import frm2 class frm1 (): .... ・form2.py from …

TypeError: 'module' object is not callable

Python 2.7 自前でモジュール作ってる癖に、たまに抜けて忘れてるエラー。 調査用のクラス作成やテスト時にいつも忘れる。 TypeError: 'module' object is not callable■解決策 モジュールにした対象のクラスを利用するには、 以下のように呼び出すこと。 モ…

郵便番号CSVの整形 on Python

Ubuntu10.4 整形してみた。整形箇所は以下。 複数行で出力されるレコードを1行にまとめる。 不要な箇所を除去 "以下に掲載がない場合" Shift_jisをUTF-8に変更して出力 テスト未実施 コードは見直す必要あり。 Python 2.6.5 #! /usr/bin/env python # codin…

ソースの文字コード

Python 2.6.4 ファイルの文字コードが同じで、 ソースコードのエンコーディングをそれぞれ指定した場合の確認

wxPython:インストール

wxPythonの導入と同時に、wxPythonのDemoを導入する。 Demoは、wxPythonの動作確認できる同時に、ソースを参照できる。 Ubuntu ■環境 Ubuntu 9.10 Python 2.6.4 wxPython2.8.10.1 aptコマンドでインストール sudo apt-get install python-wxtools wx2.8-exam…

wxPython:RegisterHotKeyはバグなのか!?

環境依存も否定できないが、動かない。 RegisterHotKeyが成功すれば、Trueを返すらしいので、試して見たところ、Falseしか返ってこない。 Note This function is currently only implemented under Windows. It is used in the Windows CE port for detectin…

wxPython:フレームテンプレート

wx.Frameのテンプレート■環境 Ubuntu 9.10 Python 2.6.4 wxPython2.8.10.1

wxPython:Links

※wxRubyも参考になる。 公式 メイン http://www.wxpython.org/ リファレンス 2.8.9.2 http://www.wxpython.org/docs/api/ wxPython 2.8.9.1 Documentation http://xoomer.virgilio.it/infinity77/wxPython/index.html※Pythonと同じsphinxを使用しており、検…

wxPython:KeyEvent

キーイベントのサンプル wxPython Demoから一部改修■環境 Windows XP Python 2.6.x wxPython2.8.x