2 행의 두 시나리오에서 파일을 읽는 방법에 차이가 있는지 확실하지 않습니다. 첫 번째 시나리오의 경우 열기 명령에 'r'
이 있고 두 번째 시나리오에는 그렇지 않습니다. 둘 다 동일한 결과를 출력합니다. 동일한 결과를 달성하기위한 단지 다른 방법일까요?여러 가지 방법으로 파일을 읽을 수 있습니까?
시나리오 1 :
def readit(filename, astr):
infile = open(filename, 'r')
content = infile.read()
infile.close()
return content.count(astr)
print(readit("payroll.txt","Sue"))
시나리오 2 :
def readit(filename, astr):
infile = open(filename)
content = infile.read()
infile.close()
return content.count(astr)
print(readit("payroll.txt","Sue"))
감사합니다! 지금은 이해. 매우 감사! –