[英]Python: Why is this code writing "None" to the file?
def obtainResumeDescriptions(self):
resumeCount = int(input("How many different versions of your resume do you use? "))
print()
resumeTrackingLog = open("resumeTrackingLog.txt", "w")
print("Please enter a brief description of each resume.")
print()
for count in range(resumeCount):
resumeNumber = str(print("Resume #", count + 1, ": ", sep=""))
resumeDescription = str(input())
print()
resumeTrackingLog.write(resumeNumber + '\n')
resumeTrackingLog.write(resumeDescription + '\n')
After executing and providing inputs, this is writing the following to the text file:执行并提供输入后,将以下内容写入文本文件:
"None Project Manager None Product Manager None Senior Manager" “无项目经理无产品经理无高级经理”
What I'm looking for is:我正在寻找的是:
"Resume #1: Project Manager Resume #2: Product Manager Resume #3: Senior Manager" “简历#1:项目经理简历#2:产品经理简历#3:高级经理”
The print
function sends output to the console, but it does not return anything. print
function 将 output 发送到控制台,但它不返回任何内容。 In Python a function that doesn't explicitly return anything implicitly returns None
.在 Python 中,没有显式返回任何内容的 function 隐式返回
None
。
You could easily replace it with an f-string:您可以轻松地将其替换为 f 字符串:
resumeNumber = f'Resume #{count + 1}: '
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.