简体   繁体   中英

How can I save multiple files with python?

I'm developing a bot for telegram that keeps open, the first time it saves the file it works normally, but the second time it overwrites the previously written file.

filename = str(uuid.uuid4())

def get_print(imagem):
    imagem = ImageGrab.grab()
    imagem.save(filename + ".png", 'png')
    return imagem

@bot.message_handler(func=get_print,commands = ['print'])
def print(imagem):
    time.sleep(1)
    bot.reply_to(imagem, "Baixe o print /down")

@bot.message_handler(commands=['down'])
def down(mensagem):
    bot.send_photo(mensagem.chat.id, photo=open(filename + ".png", 'rb',), caption = filename)

You need to change the filename, you set it once and then each time you call get_print it uses the same filename. You need to edit it in your script somewhere for each new image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM