2010-02-04 :-)
_ 朝ッ
0530 起床
_ 仕事
0830 出勤
_ [Python]Python 'import site' failed; use -v for traceback
環境: cygwin
Python のスクリプトファイル
#!/usr/bin/python import sys print sys.argv
実行すると怒られる。
% python 01.py 'import site' failed; use -v for traceback ['01.py']
-v してみる。えー
% python -v 01.py # installing zipimport hook import zipimport # builtin # installed zipimport hook 'import site' failed; traceback: ImportError: No module named site Python 2.5.2 (r252:60911, Dec 2 2008, 09:26:14) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. ['01.py'] # clear __builtin__._ # clear sys.path # clear sys.argv # clear sys.ps1 # clear sys.ps2 # clear sys.exitfunc # clear sys.exc_type # clear sys.exc_value # clear sys.exc_traceback # clear sys.last_type # clear sys.last_value # clear sys.last_traceback # clear sys.path_hooks # clear sys.path_importer_cache # clear sys.meta_path # restore sys.stdin # restore sys.stdout # restore sys.stderr # cleanup __main__ # cleanup[1] zipimport # cleanup[1] signal # cleanup[1] exceptions # cleanup sys # cleanup __builtin__ # cleanup ints # cleanup floats
[Python-ml-jp 2502] Re: 'import site' failed
対話してみる。ダメ
% python 'import site' failed; use -v for traceback Python 2.5.2 (r252:60911, Dec 2 2008, 09:26:14) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> % python 01.py 'import site' failed; use -v for traceback ['01.py']
[Python-ml-jp 2272] Re: 'import site' failed; use -v for traceback (Python 2.2.2)
PYTHONHOME に設定してみる。okだって。えー
% export PYTHONHOME=/usr % python 01.py ['01.py']
とりあえず .zshenv に書いておく
export PYTHONHOME=/usr export PYTHONPATH=/usr
説明など
[Python-ml-jp 2265] Re: 'import site' failed; use -v for traceback (Python 2.2.2)
念のために説明すると, $ PYTHONHOME=/tmp python は,python を実行するプロセスだけ環境変数 PYTHONHOME を /tmp に セットします。もとのシェルの環境変数はそのままです。 この書き方は,シェルで素早くコマンドを試験したいときには必須です。
_ [C#][.NET]C# 2次元配列の一部を2次元配列へコピーする
Buffer.BlockCopy というのを知った。ba1[ 1, 0 ] へオフセット5 でアクセスする、というのが凶悪だなあ。
Byte[,] ba1 = new Byte[4, 5]; Byte[,] ba2 = new Byte[2, 2]; Byte i = 0; for (int y = 0; y < ba1.GetLength(0); y++) { for (int x = 0; x < ba1.GetLength(1); x++) { ba1[y, x] = i; i++; } } Buffer.BlockCopy(ba1, 6, ba2, 0, 2); Buffer.BlockCopy(ba1, 11, ba2, 2, 2); Console.WriteLine("コピー元"); for (int y = 0; y < ba1.GetLength(0); y++) { for (int x = 0; x < ba1.GetLength(1); x++) { Console.Write("{0:X2} ", ba1[y, x]); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("コピー先"); for (int y = 0; y < ba2.GetLength(0); y++) { for (int x = 0; x < ba2.GetLength(1); x++) { Console.Write("{0:X2} ", ba2[y, x]); } Console.WriteLine(); } Console.WriteLine();
出力
コピー元 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 コピー先 06 07 0B 0C
_ [C#][.NET]C# 2次元配列の全体を2次元配列へコピーする
時間を計測してみた。前半が Buffer.BlockCopy 、後半が 2重ループ。
int height = 9000; int width = 9000; Byte[,] src = new Byte[height, width]; Byte[,] dst = new Byte[height, width]; Byte i = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { src[y, x] = i; i++; } } Stopwatch sm = new Stopwatch(); sm.Start(); int srcpos = 0; int dstpos = 0; for (int y = 0; y < height; y++) { Buffer.BlockCopy(src, srcpos, dst, dstpos, width); srcpos += width; dstpos += width; } sm.Stop(); Console.WriteLine("copy1: {0} msec", sm.ElapsedMilliseconds); sm.Reset(); sm.Start(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { dst[y, x] = src[y, x]; } } sm.Stop(); Console.WriteLine("copy2: {0} msec", sm.ElapsedMilliseconds);
ふむ
copy1: 93 msec copy2: 1185 msec
_ [C#][.NET]C# 2次元配列の全体を2次元配列へコピーする(2)
コピー元とコピー先の要素数が同じならばこれでも ok なのか
Buffer.BlockCopy(src, 0, dst, 0, height * width);
_ 見合いのときはちゃんと「アニオタで声オタでゲーオタですがよろしいでしょうか」と自己紹介しようと思う
( via 結婚・恋愛ニュースぷらす:30歳女性 「大切な処女を捧げた ステキな彼氏の正体はオタク。ショックで泣きそうです」 )
いつも ohguchi がそう言ってたことを思い出した。
見合いの予定なんてないけど。
[ツッコミを入れる]