xiaoyuer000 发表于 2021-11-26 21:32:52

open()函数无法打开桌面TXT文件

本帖最后由 xiaoyuer000 于 2021-11-27 10:49 编辑

桌面创建TXT文件 open()函数无法打开

jackz007 发表于 2021-11-26 22:00:15

本帖最后由 jackz007 于 2021-11-26 22:02 编辑

         把 open() 里的文件名改成"sss.txt.txt" , Windows 资源器在默认情况下开启了 "不显示已知类型文件扩展名" 的选项,使得一个看上去是 "sss.txt" 的文件名实际上是 "sss.txt.txt"

xiaoyuer000 发表于 2021-11-26 22:11:37

jackz007 发表于 2021-11-26 22:00
把 open() 里的文件名改成"sss.txt.txt" , Windows 资源器在默认情况下开启了 "不显示已知类型 ...

f = open(r"C;\Users\goodb\Desktop\sss.txt.txt")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
    f = open(r"C;\Users\goodb\Desktop\sss.txt.txt")
FileNotFoundError: No such file or directory: 'C;\\Users\\goodb\\Desktop\\sss.txt.txt'

jackz007 发表于 2021-11-26 22:17:16

xiaoyuer000 发表于 2021-11-26 22:11
f = open(r"C;%users\goodb\Desktop\sss.txt.txt")
Traceback (most recent call last):
File "", li ...

      r"C;\Users\goodb\Desktop\sss.txt.txt"
      看出问题了?

列斗 发表于 2021-11-26 22:19:45

错把引号当冒号

xiaoyuer000 发表于 2021-11-26 22:24:39

jackz007 发表于 2021-11-26 22:17
r"C;%users\goodb\Desktop\sss.txt.txt"
      看出问题了?

f = open(r"C:Users\goodb\Desktop\sss.txt.txt")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
    f = open(r"C:Users\goodb\Desktop\sss.txt.txt")
FileNotFoundError: No such file or directory: 'C:Users\\goodb\\Desktop\\sss.txt.txt'

xiaoyuer000 发表于 2021-11-26 22:31:11

列斗 发表于 2021-11-26 22:19
错把引号当冒号

f = open(r"C:Users\goodb\Desktop\sss.txt.txt")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
    f = open(r"C:Users\goodb\Desktop\sss.txt.txt")
FileNotFoundError: No such file or directory: 'C:Users\\goodb\\Desktop\\sss.txt.txt'
改了也找不到桌面文件

jackz007 发表于 2021-11-26 22:38:59

       你还得试试 "sss.txt" 啊,这个也得教吗?

xiaoyuer000 发表于 2021-11-26 22:41:51

f = open(r"C:\Users\goodb\Desktop\sss.txt.txt")
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
    f = open(r"C:\Users\goodb\Desktop\sss.txt.txt")
FileNotFoundError: No such file or directory: 'C:\\Users\\goodb\\Desktop\\sss.txt.txt'

列斗 发表于 2021-11-26 23:25:34

xiaoyuer000 发表于 2021-11-26 22:31
f = open(r"C:Users\goodb\Desktop\sss.txt.txt")
Traceback (most recent call last):
File "", li ...

f = open(r"C:\Users\goodb\Desktop\sss.txt")
试一下这个

xiaoyuer000 发表于 2021-11-27 10:36:54

C:\Users\Administrator\Desktop\record.txt
谢谢大家问题找到了 新创建文件地址输入错误
f = open(r"C:\Users\Administrator\Desktop\record.txt")
>>> f
<_io.TextIOWrapper name='C:\\Users\\Administrator\\Desktop\\record.txt' mode='r' encoding='cp936'>

xiaoyuer000 发表于 2021-11-27 10:46:47

列斗 发表于 2021-11-26 23:25
试一下这个


C:\Users\Administrator\Desktop\record.txt
谢谢大家问题找到了 新创建文件地址输入错误
f = open(r"C:\Users\Administrator\Desktop\record.txt")
>>> f
<_io.TextIOWrapper name='C:\\Users\\Administrator\\Desktop\\record.txt' mode='r' encoding='cp936'>

列斗 发表于 2021-11-28 22:08:45

用户文件夹。。。
页: [1]
查看完整版本: open()函数无法打开桌面TXT文件