python 3 :号码自动来

python 3 :number coming automatically

myimage

嗨,

我在下面写了这段代码,每次我 运行 它都会给出一些数字,比如 16、23 见附件的 jpeg 图片,它有数字 13,有人可以解释一下吗?

from sys import argv
script, filename = argv

print ("I will show you magic")
print (open(filename).read())

target = open(filename, "w")
target.truncate()

# now i will show you more magic

print("lets do this")

line1 = input("what do you want to print type it in, ok?, ")
line2 = input("i dont understand this, ")
line3 = input("type again please, ")
print (target.write(f"{line1} \n{line2} \n{line3}"))
target = open(filename)
print (target.read())

您正在打印 target.write() 的 return 值。该方法 returns 写入的字符数。来自 TextIOBase.write() documenatation:

Write the string s to the stream and return the number of characters written.

13 表示您向文件写入了 13 个字符。如果你选择 26,那么你向文件写入了两倍的信息。如果您不想打印它,只需删除 print() 调用,只调用 target.write().