You return four variables s1,s2,s3,s4 and receive them using a single variable obj. This is what is called a tuple, obj is associated with 4 values, the values of s1,s2,s3,s4. So, use index as you use in a list to get the value you want, in order.
Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
print obj[3] + " is a benefit of functions!"
Answer from Aswin Murugesh on Stack OverflowYou return four variables s1,s2,s3,s4 and receive them using a single variable obj. This is what is called a tuple, obj is associated with 4 values, the values of s1,s2,s3,s4. So, use index as you use in a list to get the value you want, in order.
Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
print obj[3] + " is a benefit of functions!"
You're returning a tuple. Index it.
Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
python - PIL library Image.fromarray() causes AttributeError: 'tuple' object has no attribute '__array_interface__' - Stack Overflow
AttributeError: 'tuple' object has no attribute '' Error Help
AttributeError: 'tuple' object has no attribute 'enter'
AttributeError: 'tuple' object has no attribute - Lemma Soft Forums
Videos
It's not clear from your description whether camera1[2] is a flat list of consecutive R, G, B, A values, or whether it's a list of RGBA tuples. So I'll show you how to read both options. ;)
Your main problem is that your data doesn't contain width and height information, so we need to supply that info, somehow. One way to do that would be to read the data into a 3D Numpy array of the correct shape. But we can also do it directly in PIL by using the appropriate Image methods.
For my demonstrations I use Python loops to create some simple RGBA data.
This script creates a list of RGBA tuples.
from PIL import Image
maxval = 255
width, height = 400, 300
# Display size info
size = width * height
fmt = 'Width: {}, Height: {}, Pixels: {}, Bytes: {}'
print(fmt.format(width, height, size, size * 4))
# Make a 2D gradient that starts at black in the top left corner,
# with red & green increasing horizontally, blue increasing vertically.
# This would be much faster using Numpy instead of Python loops.
pixels = []
# Make all pixels fully opaque
alpha = maxval
for y in range(height):
blu = maxval * y // height
for x in range(width):
red = gre = maxval * x // width
# Make a single RGBA pixel as a tuple
pix = red, gre, blu, alpha
# And save it
pixels.append(pix)
# Show that the size of `pixels` is correct and show the first few pixels
print('Size:', len(pixels))
print(pixels[:8])
# Make a new image object. All pixels are set to black.
img = Image.new('RGBA', (width, height))
# Copy the pixel data to the Image
img.putdata(pixels)
img.show()
img.save('test1.png')
output
Width: 400, Height: 300, Pixels: 120000, Bytes: 480000
Size: 120000
[(0, 0, 0, 255), (0, 0, 0, 255), (1, 1, 0, 255), (1, 1, 0, 255), (2, 2, 0, 255), (3, 3, 0, 255), (3, 3, 0, 255), (4, 4, 0, 255)]
test1.png

This script creates a flat list of R, G, B, A values. It uses a Python 3 bytes object, so it won't work properly on Python 2.
from PIL import Image
maxval = 255
width, height = 400, 300
# Display size info
size = width * height
fmt = 'Width: {}, Height: {}, Pixels: {}, Bytes: {}'
print(fmt.format(width, height, size, size * 4))
# Make a 2D gradient that starts at black in the top left corner,
# with red & green increasing horizontally, blue increasing vertically.
# This would be much faster using Numpy instead of Python loops.
rgba = []
# Make all pixels fully opaque
alpha = maxval
for y in range(height):
blu = maxval * y // height
for x in range(width):
red = gre = maxval * x // width
# Make a single RGBA pixel as a tuple
pix = red, gre, blu, alpha
# And save each of red, gre, blu, alpha to rgba.
# By using `.extend` we create a flat list
rgba.extend(pix)
# Show that the size of `rgba` is correct and show the first few values.
print('Size:', len(rgba))
print(rgba[:32])
# Convert the rgba list to bytes.
rgba = bytes(rgba)
# Make a new image object from the bytes
img = Image.frombytes('RGBA', (width, height), rgba)
img.show()
img.save('test2.png')
output
Width: 400, Height: 300, Pixels: 120000, Bytes: 480000
Size: 480000
[0, 0, 0, 255, 0, 0, 0, 255, 1, 1, 0, 255, 1, 1, 0, 255, 2, 2, 0, 255, 3, 3, 0, 255, 3, 3, 0, 255, 4, 4, 0, 255]
The file 'test2.png' is identical to 'test1.png'.
Earlier answer is TLDR;
So i will tell the exact reason
This error is mostly because : In Image.fromarray(arr) you might have given tuple in place of argument:arr where it excepts a numpy array
I am trying to make a discord bot that would turn a message into lowercase. I am encountering an error, as the title suggests, "AttributeError: 'tuple' object has no attribute 'lower'. "
Here is my code if anyone can help.
https://hastebin.com/ibareyilax.py
If this is the wrong subreddit I don't mind taking down my post and posting it elsewhere.
from kubernetes import client, config
config.load_kube_config()
v1 = client.CoreV1Api()
print("Listing services with their IPs:")
ret = v1.list_service_for_all_namespaces_with_http_info(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name)) This throws this error: File "filename.py", line 8, in <module> for i in ret.items: AttributeError: 'tuple' object has no attribute 'items'
But when I simply print(ret), it certainly LOOKS like a tuple, which means I should be able to iterate through with tuple.items, no?
Hello!
i have created a list in my code that ends in me having a list of coordinates listed as such:
0: (x,y)
1: (x,y)
2: (x,y) …..
that coordinates belong to little squares that have corresponding colours.
i wanted to make it:
0: (x,y,’RED’)
1: (x,y,’BLUE’)
2: (x,y,’BLUE’) …..
but when i call my list and do list[0].append(‘RED’) i get ‘tuple’ object has no attribute ‘append’
i wanted to do it this way because there can be a lot of boxes and i’d like to do it inside a for loop
any help??