Oracle データベースから配列にデータを読み取った後、perl ハッシュをネストされたキー付き Python ディクショナリに変換する必要があります。これを行う最も効率的な方法は何ですか? 既存の Perl コード (私は Perl をまったく知りません) は次のようになります。
# read the data and place into a species hash (sphash) and a data hash (tmphash)
my (@lnarr, %sphash, %tmphash, $tmpln, $tmpsel, $x, $datetime) ;
while (@lnarr = $csr->fetchrow_array) {
$datetime = $lnarr[4].'-'.$lnarr[5] ;
$tmpln = join '_', $lnarr[8], $lnarr[9] ;
$sphash{$lnarr[7]} = 'x';
$tmphash{$lnarr[0].'_'.$lnarr[1].'_'.$lnarr[2].'_'.$lnarr[3].'_'.$datetime.'_'.$lnarr[6]}{$lnarr[7]} .= $tmpln ;
} #while line
ネストされた辞書を作成する最も効率的なルートが何であるかはわかりません...どんなガイダンスも素晴らしいでしょう。
私の最初のコードは次のようになりますが、おそらく非常に間違っていることは承知しています(私もPythonを学んでいます):最初の数行は、この投稿に基づいて、Oracle出力から辞書にタプルを読み取っています:こちら
#this is creating the dictionary from the data
cursor.execute(query, cruise6_input=cruise6_input)
desc=[d[0] for d in cursor.description]
result=[dict(zip(desc,line)) for line in cursor]
station=[r['STATION'] for r in result]
time=[r['GMT_TIME']for r in result]
svspp=[r['SVSPP'] for r in result]
expcatchwt=[r['EXPCATCHWT'] for r in result]
beglat=[r['BEGLAT'] for r in result]
expcatchnum=[r['EXPCATCHNUM'] for r in result]
cruise=[r['CRUISE'] for r in result]
towdate=[r['BEGIN_GMT_TOWDATE'] for r in result]
stratum=[r['STRATUM'] for r in result]
beglon=[r['BEGLON'] for r in result]
tmpln=zip(expcatchwt,expcatchnum)
tmphash=zip(station,time,beglat,cruise,towdate,stratum,beglon)
keys=zip(tmphash,svspp)
tmphash[svspp]=tmpln の出力を取得するにはどうすればよいですか? tmphash[svspp] を出力すると、結果は単に {} になります....