In python, the problem about using format to open the document
ringa_lee
ringa_lee 2017-06-28 09:25:15
0
2
1031

Use the format method to open the image, but I don’t know what this code means. See the screenshot?

with open ("map{n:02d}.png".format(n=0), "wb") as f:  # format 02d 两位整数
    f.write(data)

ringa_lee
ringa_lee

ringa_lee

reply all(2)
仅有的幸福

The

with statement is a context management method for opening and closing files. For example, the general opening posture is

file = open("filename", 'wb')
# do something
file.close()

With context management, withAfter the code block is executed, the internal method will be called to directly close the file. There is no need to manually call the close() method, which is the way given in the question.
Of course format is a method of formatting strings. The position of {n} is reserved in the string. n will be used as the key of a keyword parameter. After the value is passed in, the passed in will be used. valuereplacement, so the position of {n:02d} in the question will be replaced by the integer string received by n. If only {} is left in the string, and no key value is specified, then the parameter passed in format will be used as a positional parameter, and will be filled in order one by one corresponding to the {} in the string.

漂亮男人

Format string

Equivalent to: "map" + "00" + ".png"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template