林打印時遇到問題在我的職務返回值幫助的Python
def readfile(filename):
'''
Reads the entire contents of a file into a single string using
the read() method.
Parameter: the name of the file to read (as a string)
Returns: the text in the file as a large, possibly multi-line, string
'''
try:
infile = open(filename, "r") # open file for reading
# Use Python's file read function to read the file contents
filetext = infile.read()
infile.close() # close the file
return filetext # the text of the file, as a single string
except IOError:
()
def main():
''' Read and print a file's contents. '''
file = input(str('Name of file? '))
readfile(file)
如何保存的ReadFile的值到不同的變量,然後打印您保存的ReadFile的返回值的變量的值一個返回值?
@JonClements謝謝,小姐編輯。 :) –