OSError: [Errno 22] Invalid argument:

来源:互联网 发布:淘宝现代热水器怎么样 编辑:程序博客网 时间:2024/06/10 21:32

Python读文件操作报错

>>> infile=open("C:\number.txt","r")


Traceback (most recent call last):
  File "<pyshell#15>", line 1, in <module>
    infile=open("C:\number.txt","r")

OSError: [Errno 22] Invalid argument: 'C:\number.txt'

>>> infile=open("C:\number.txt","r")

1:如果确认目录下有该文件时,注意将这里的文件扩展名打上对勾

2:open函数定义

<variable>=open(<name>,<mode>)

在此处,name为磁盘文件名

格式应为路径+文件名+后缀。例如d:/abc.exe ‘d:/’为盘符,‘abc’为文件名,‘.exe’就是后缀。

所以 infile=open("C:\number.txt","r")

应该改为infile=open("c:/number.txt","r")

同时应该把隐藏后缀名打上勾

阅读全文
0 0