|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求教:
直接>>> f=open('/Users/simonwang/Desktop/Python学习/29a')
报错
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
f=open('/Users/simonwang/Desktop/Python学习/29a')
FileNotFoundError: [Errno 2] No such file or directory: '/Users/simonwang/Desktop/Python学习/29a'
文件名加上格式后缀.rtf就没报错
>>> f=open('/Users/simonwang/Desktop/Python学习/29a.rtf')
>>> f
<_io.TextIOWrapper name='/Users/simonwang/Desktop/Python学习/29a.rtf' mode='r' encoding='UTF-8'>
然后试图读取文档内容:
>>> f.read()
热闹了,出了以下一堆乱码。请问怎么回事?
"{\\rtf1\\ansi\\ansicpg936\\cocoartf2511\n\\cocoatextscaling0\\cocoaplatform0{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;\\f1\\fnil\\fcharset134 PingFangSC-Regular;}\n{\\colortbl;\\red255\\green255\\blue255;}\n{\\*\\expandedcolortbl;;}\n\\paperw11900\\paperh16840\\margl1440\\margr1440\\vieww10800\\viewh8400\\viewkind0\n\\pard\\tx566\\tx1133\\tx1700\\tx2267\\tx2834\\tx3401\\tx3968\\tx4535\\tx5102\\tx5669\\tx6236\\tx6803\\pardirnatural\\partightenfactor0\n\n\\f0\\fs24 \\cf0 DJ: To start a new txt file.\\\nGLOK\n\\f1 \\\nDJ: Put names in.\\\n\n\\f0 GL\n\\f1 \\'a3\\'baHow many people?\\\nDJ: Twenty-five\\\n\n\\f0 GL\n\\f1 \\'a3\\'baGot it.\\\nDJ: Thank you!\\\n\\\n===========================\\\n\\\n\n\\f0 DJ: To start a new txt file.2\\\nGLOK2\n\\f1 \\\nDJ: Put names in.2\\\n\n\\f0 GL\n\\f1 \\'a3\\'baHow many people?2\\\nDJ: Twenty-five2\\\n\n\\f0 GL\n\\f1 \\'a3\\'baGot it.2\\\nDJ: Thank you!2\\\n\\\n============================\\\n\\\n\n\\f0 DJ: To start a new txt file.3\\\nGLOK3\n\\f1 \\\nDJ: Put names in.3\\\n\n\\f0 GL\n\\f1 \\'a3\\'baHow many people?3\\\nDJ: Twenty-five3\\\n\n\\f0 GL\n\\f1 \\'a3\\'baGot it.3\\\nDJ: Thank you!3\\\n\\\n\\\n}"
|
|