Python, 配列のプリント

    print >> wf, 'color red #0:%(list1)s.a@Ca' % {'list1':residue_list[j][i]}
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.TextIOWrapper'

配列を確認してみると、空の配列があったのでif文を使って配列に1つ以上値が入っているものだけをプリントするようにした。

if 0 > len(list):
   print '%(list1)s' % {'list1':list}

これでOK!かと思いきや・・・

    print >> wf, 'color red #0:%(list1)s.a@Ca' % {'list1':residue_list[j][i]};
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and
'_io.TextIOWrapper'

全体に括弧が無いから?

    print >> (wf, 'color red #0:%(list1)s.a@Ca' % {'list1':residue_list[j][i]})
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and
'tuple'

括弧つけてもダメ。type(s)がメソッドとタプルに使われるってこと?
そして、調べるうちにこのprintでの外部出力の方法がpython2の記法だということがわかり、python3の記法に変えてみる。

print('color red #0:%s.a@Ca' % residue_list[j][i], file = wf)

通った~!
あとから調べてわかったのが、最初にやっていたのは辞書型にしてプリントしようとしていたみたい。普通に、変数が指しているオブジェクトを表示したい場合は最後の書き方で良かったということです。