with open('./matmul.py') as f:
try:
while True:
line=next(f)
print(line)
except StopIteration:
pass
報錯:
IOError: [Errno 2] No such file or directory: './matmul.py'
解決:
os.open是針對當前工作目錄中的文件進行打開操作的,需要修改工作目錄之后再運行這個方法
import os
print os.getcwd()#顯示當前工作目錄
os.chdir('the_path_of_the_file_whitch_you_want_to_open.txt') #修改當前工作目錄
文件名要帶后綴