python中os.open,报错:No such file or directory:


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') #修改当前工作目录

文件名要带后缀

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM