使用Python读取RTF文件
- 使用striprtf rtf_to_text读取RTF文件
- 无法读取URL,在代码中需要进行哪些更改?
输入 获取 [
> > 上获取最新新闻更新
在所需的输出 获取 [emage  protinted]
python代码: - python代码: - python代码: -
import os
from striprtf.striprtf import rtf_to_text
import pandas as pd
from os import path
path_of_the_directory= r'C:\Users\Documents\filename.rtf'
print("Files and directories in a specified path:")
for filename in os.listdir(path_of_the_directory):
f = os.path.join(path_of_the_directory,filename)
if os.path.isfile(f):
print(f)
open_rtf_file=open(f,'r')
file_content_read=open_rtf_file.read()
text_content=rtf_to_text(file_content_read)
print(text_content)
- reading RTF file using striprtf
- rtf_to_text not able to read URL,what changes need to make in the code?
Input
Get latest news update at [email protected]
Output
Get latest news update at
Desired Output
Get latest news update at [email protected]
python code:-
import os
from striprtf.striprtf import rtf_to_text
import pandas as pd
from os import path
path_of_the_directory= r'C:\Users\Documents\filename.rtf'
print("Files and directories in a specified path:")
for filename in os.listdir(path_of_the_directory):
f = os.path.join(path_of_the_directory,filename)
if os.path.isfile(f):
print(f)
open_rtf_file=open(f,'r')
file_content_read=open_rtf_file.read()
text_content=rtf_to_text(file_content_read)
print(text_content)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您将文件视为目录。您的
path_of_the_directory
Varaible实际上是RTF文件名的路径。不知道您在运行时遇到的特定错误,在我看来是问题所在。修复它的一种简单方法是检查以确保在调用os.listdir
之前的路径是目录,就像我在下面的示例中所做的那样。It looks like you are treating a file as a directory. your
path_of_the_directory
varaible is actually the path to a rtf file name. Without knowing what specific error you are getting at runtime, it looks to me like that is the problem. An easy way to fix it is to check to make sure the path is a directory prior to callingos.listdir
like I do in the example below.