意図と一致しているか? 不安ではありますが。
ソースコードのサンプルです。(a.py)
python
1# -*- coding: utf-8 -*-
2
3import codecs
4
5fin = codecs.open('fopeninout-1.txt', 'r', 'utf-8')
6fout = codecs.open('fopeninout-2.txt', 'w', 'utf-8')
7
8i = 0
9
10bufs = fin.readlines()
11maxline = len(bufs)
12
13for i in range(maxline,0,-1):
14 if ( i % 2 ) :
15 fout.write(bufs[i])
16
17fin.close()
18fout.close()
データを適当に作ります。
shell
1find / -print | head -100 > fopeninout-1.txt
実行してみます。
shell
1# python a.py
2# ls fopeninout*.txt
3-rw-r--r-- 1 root root 3820 10月 17 23:44 2016 fopeninout-1.txt
4-rw-r--r-- 1 root root 1930 10月 17 23:47 2016 fopeninout-2.txt
半分の行が出力されているか?
shell
1# wc -l fopeninout*.txt
2 100 fopeninout-1.txt
3 50 fopeninout-2.txt
4 150 合計
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/18 11:25
2016/10/18 14:04