[問題] os.listdir後open text問題
python 新手想請問openfile的問題
一段code如下
# -*- coding: UTF-8 -*-
import os, sys
path= "/home/puoud/documents"
dirs = os.listdir(path)
for file in dirs:
print file
若我想將documents內的每一個.txt都read
請問在下一個段落open(file,'r').open()
出錯在哪裡?
出錯
IOError: [Errno 2] No such file or directory: xxxx.txt
請問怎麼打比較正確?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.240.33.180
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1461566266.A.5EF.html
→
04/25 14:55, , 1F
04/25 14:55, 1F
感謝!
推
04/25 17:20, , 2F
04/25 17:20, 2F
解決了,感謝!
※ 編輯: proud (180.204.20.230), 04/25/2016 22:07:37
推
04/25 22:38, , 3F
04/25 22:38, 3F
→
04/30 12:22, , 4F
04/30 12:22, 4F
Python 近期熱門文章
PTT數位生活區 即時熱門文章