python 3:数字自动出现

时间:2017-04-27 19:57:50

标签: python python-3.6

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())

1 个答案:

答案 0 :(得分:2)

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

  

将字符串 s 写入流并返回写入的字符数。

13表示你为一个文件写了13个字符。如果你是26,那么你写了两倍的文件信息。如果您不想打印,只需移除print()来电,只需拨打target.write()