-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d1bd1e
commit 5ec7398
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
''' | ||
1列目をcol1.txtに,2列目をcol2.txtに保存 | ||
各行の1列目だけを抜き出したものをcol1.txtに,2列目だけを抜き出したものをcol2.txtとしてファイルに保存せよ.確認にはcutコマンドを用いよ. | ||
参考 12.pyの答え : https://qiita.com/segavvy/items/51a515c19bcd29b13b7f | ||
参考 open()について : https://note.nkmk.me/python-file-io-open-with/ | ||
参考 明示的な改行 : https://www.glamenv-septzen.net/view/185 | ||
参考 ジェネレータについて(先頭の関数について) : https://qiita.com/tomotaka_ito/items/15b5999c76001dbc9a58 | ||
: https://qiita.com/tomotaka_ito/items/35f3eb108f587022fa09 | ||
''' | ||
|
||
file_name = "hightemp.txt" | ||
|
||
with open(file_name) as file, open("col1.txt", "w") as col1, \ | ||
open("col2.txt", "w") as col2: | ||
|
||
lines = file.readlines(); | ||
|
||
for line in lines: | ||
cols = line.split("\t") | ||
col1.write(cols[0] + "\n") | ||
col2.write(cols[1] + "\n") | ||
|
||
|
||
''' | ||
cut 参考url | ||
http://x68000.q-e-d.net/~68user/unix/pickup?cut | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
''' | ||
1列目をcol1.txtに,2列目をcol2.txtに保存 | ||
各行の1列目だけを抜き出したものをcol1.txtに,2列目だけを抜き出したものをcol2.txtとしてファイルに保存せよ.確認にはcutコマンドを用いよ. | ||
参考 12.pyの答え : https://qiita.com/segavvy/items/51a515c19bcd29b13b7f | ||
参考 open()について : https://note.nkmk.me/python-file-io-open-with/ | ||
参考 明示的な改行 : https://www.glamenv-septzen.net/view/185 | ||
参考 ジェネレータについて(先頭の関数について) : https://qiita.com/tomotaka_ito/items/15b5999c76001dbc9a58 | ||
: https://qiita.com/tomotaka_ito/items/35f3eb108f587022fa09 | ||
''' | ||
|
||
class ReiteratableWrapper(object): | ||
def __init__(self, f): | ||
self._f = f | ||
|
||
def __iter__(self): | ||
return self._f() | ||
|
||
file_name = "hightemp.txt" | ||
|
||
with open(file_name) as file, open("col1.txt", "w") as col1, \ | ||
open("col2.txt", "w") as col2: | ||
|
||
lines = file.read(); | ||
print(type(lines)) | ||
|
||
# lines = ReiteratableWrapper(lines) | ||
# linesもう一度ループ文で使いたかった | ||
# イテレータ、ジェンレータが原因か? | ||
|
||
print('col1への書き込み') | ||
for line in lines: | ||
cols = line.split("\t") | ||
#print(cols[0]) | ||
col1.write(cols[0] + "\n") | ||
|
||
# 何も書き込まれない | ||
print('col2への書き込み') | ||
for line in lines: | ||
cols = line.split("\t") | ||
#print(cols[1]) | ||
col2.write(cols[1] + "\n") | ||
|
||
|
||
''' | ||
cut 参考url | ||
http://x68000.q-e-d.net/~68user/unix/pickup?cut | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
高知県 | ||
埼玉県 | ||
岐阜県 | ||
山形県 | ||
山梨県 | ||
和歌山県 | ||
静岡県 | ||
山梨県 | ||
埼玉県 | ||
群馬県 | ||
群馬県 | ||
愛知県 | ||
千葉県 | ||
静岡県 | ||
愛媛県 | ||
山形県 | ||
岐阜県 | ||
群馬県 | ||
千葉県 | ||
埼玉県 | ||
大阪府 | ||
山梨県 | ||
山形県 | ||
愛知県 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
江川崎 | ||
熊谷 | ||
多治見 | ||
山形 | ||
甲府 | ||
かつらぎ | ||
天竜 | ||
勝沼 | ||
越谷 | ||
館林 | ||
上里見 | ||
愛西 | ||
牛久 | ||
佐久間 | ||
宇和島 | ||
酒田 | ||
美濃 | ||
前橋 | ||
茂原 | ||
鳩山 | ||
豊中 | ||
大月 | ||
鶴岡 | ||
名古屋 |