首页 > 编程语言 > 详细

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

时间:2015-11-24 20:36:36      阅读:925      评论:0      收藏:0      [点我收藏+]

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

文件名要带后缀

 

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

原文:http://www.cnblogs.com/wwww/p/4992667.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!