python中打开TXT文件报错

    xiaoxiao2021-03-25  181

    在IDLE命令行引用一文件夹下的函数,来了条错误提示:FileNotFoundError: [Errno 2] No such file or directory: 'testSet.txt'

    错误的原因工作路径没有切换到这个TXT文件所在的文件夹下;

    解决方法是在命令行敲入以下几行代码:

                         >>> import os

                         >>> print os.getcwd()       // 打印出当前工作目录 

                         >>> os.chdir('the dir which include the file a.txt') #修改当前工作目录

    转载请注明原文地址: https://ju.6miu.com/read-11726.html

    最新回复(0)