Python Forum
generate filename of value and extend
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
generate filename of value and extend
#1
from PIL import Image
import sys

rr = input('R > code: ')
gg = input('G > code: ')
bb = input('B > code: ')
 
filename = ( str(rr)+str(gg)+str(bb)  )
suffix =  ".png"

im.save("/home/marre/XY-Kordinaterna/PAINT_BILDER/filename + suffix")
#----------------------------------------------------------------------------
inserted values to the program

R > code: 1
G > code: 2
B > code: 3

my result: filename + suffix = 123.png

I get a error message that i cant understand
Error:
Traceback (most recent call last): File "/home/marre/XY-Kordinaterna/4_från_cluster_EN_FÄRG_test.py", line 48, in <module> im.save("/home/marre/XY-Kordinaterna/PAINT_BILDER/filename + suffix") File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1662, in save format = EXTENSION[ext] KeyError: ''
I an greatfull for help
br Marre
Reply
#2
im.save("/home/marre/XY-Kordinaterna/PAINT_BILDER/{}{}".format(filename, suffix))
The format method of strings replaces the {}'s with the variables passed to it. It also allows lots of formatting options, but those are not needed here.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
or if running python 3.6.0 or newer:
im.save(f'/home/marre/XY-Kordinaterna/PAINT_BILDER/{filename}.png')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  View and extend native python class PythonDev 2 1,658 Oct-24-2020, 08:59 PM
Last Post: Gribouillis
  Why the this extend example is printing 2 two times? sbabu 1 1,479 Jan-12-2020, 07:30 AM
Last Post: Gribouillis
  How to extend the sclale of a graph? Krszt 1 2,319 Nov-13-2018, 11:16 AM
Last Post: Larz60+
  Extend the scale Krszt 1 2,700 Nov-05-2018, 01:16 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020