2024-06-17 15:02:29 发布
网友
在Python中,如何像在Java中使用InputStream那样只读取文件内容(不包括属性和文件名)? 我需要一个方法,为各种文件格式工作
我试过了
with open(filePath, "rb") as imageFile: str = base64.b64encode(imageFile.read()) M=str.decode() print(M)
问题是,在那个块之后,任何对象都会出错
最基本的方法是:
with open("filename.txt") as f: contents = f.read()
变量内容现在将包含文件中所有内容的字符串。更多信息在Python文档(https://docs.python.org/3/tutorial/inputoutput.html)中。在
最基本的方法是:
变量内容现在将包含文件中所有内容的字符串。更多信息在Python文档(https://docs.python.org/3/tutorial/inputoutput.html)中。在
相关问题 更多 >
编程相关推荐