码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-11-24 20:37:08      阅读:172      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!