我有一個文本文件:Python讀物在一個文件中的每個字符串
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
我希望能夠檢索每個字符串,並將其轉換爲整數數據類型,但我在
一段代碼結果tile_map = open('background_tiles.txt','r');
for line in tile_map:
for string in line:
self.type = int(string);
檢索數據並將其成功轉換的正確方法是什麼?
相關:[將文件字符串讀入數組(以pythonic方式)](http://stackoverflow.com/a/11052673/4279) – jfs