用大学python的水平帮我定义一个ReadFile函数,实现文本文件的读取
时间: 2023-05-28 20:02:28 浏览: 72
用python实现文件的读取
def ReadFile(filename):
"""
This function reads the contents of a text file and returns them as a string.
Parameters:
filename (str): The filename (including the path if it is not in the current directory) of the file to be read.
Returns:
A string containing the contents of the file.
"""
with open(filename, 'r') as f:
file_contents = f.read()
return file_contents
阅读全文