Last active
April 3, 2016 07:20
-
-
Save longjie/714561d9d3bfcf70d7695e37dd204d19 to your computer and use it in GitHub Desktop.
スペース区切りのファイルに対するデータの読み書き
This file contains hidden or 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
#!/usr/bin/env python | |
from __future__ import print_function | |
data = [['a', 'b', 'c'], | |
['d', 'e', 'f'], | |
['g', 'h', 'i']] | |
# write data | |
with open('data.txt', 'w') as file: | |
[file.write(' '.join(x)+'\n') for x in data] | |
# read data | |
with open('data.txt', 'r') as file: | |
data = [x.split() for x in file] | |
print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
とすると評価されるがこれだとリスト内包表記の方がいい。