问题
This is what I'm inputting:
type = 'filename'
im.save(type, '.png')
and what this is supposed to do is save the file in a .png format but with the variable as the name, I'm just not 100% sure how the format/syntax is supposed to be laid out.
Is it the same as if I wanted to print the variable:
Print(type, "This shows up beside the type I think")
edit, Don't pay to much attention to the list, it's mostly there as an example. I not sure how to have a variable right beside a Plain text word like this im.save(type, 'PLAINTEXT')
回答1:
If you're trying to use PIL, please, use it like this:
file_name = 'my_file'
im.save( file_name + '.png' )
will result in my_file.png
saved to your disk.
回答2:
I think what you want is string formatting:
type = 'filename'
im.save("{0}.png".format(type))
This will create filename.png
.
Also 'Print' != 'print'
.
来源:https://stackoverflow.com/questions/23765021/using-a-variable-as-a-save-file-name-im-savetype-png