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 Overflow
🌐
Python Forum
python-forum.io › thread-33245.html
AttributeError: 'tuple' object has no attribute 'format'
Confuse where is the error because execute some parts of codes half code run and half give me an error AttributeError: 'tuple' object has no attribute 'format' def __str__(self): return ('{} : {}','[]').format(self._word, self._coords)Erro...
Discussions

'AttributeError: 'tuple' object has no attribute 'format'
╰─± ./tagger.py /Users/noah/Downloads/01-Jan-2018_to_23-Mar-2018.csv /Users/noah/Downloads/01-Jan-2018_to_23-Mar-2018\ \(1\).csv --refunds /Users/noah/Downloads/01-Jan-2018_to_23-Mar-2018\ \(2\).cs... More on github.com
🌐 github.com
3
March 23, 2018
ERROR: AttributeError: 'tuple' object has no attribute 'to'
------------------------------... {:.6f}'.format( 17 epoch, batch_idx * len(data), len(train_loader.dataset), 18 100. * batch_idx / len(train_loader), loss.item())) 20 for epoch in range(1, 11): ---> 21 train(epoch) Cell In[118], line 10, in train(epoch) 8 model.train() 9 for batch_idx, (data, target) in enumerate(train_loader): ---> 10 data, target = data.to(device), target.to(device) 11 optimizer.zero_grad() 12 output = model(data) AttributeError: 'tuple' object has no attribute ... More on github.com
🌐 github.com
3
January 1, 2024
'tuple' object has no attribute 'to' in pytorch
I got this error while trying to test CNN model. I already checked type about this error point’variable. Here is error point 10. imgs = imgs.to(device) #imgs type —> 11 … More on discuss.pytorch.org
🌐 discuss.pytorch.org
1
0
June 19, 2021
Python AttributeError: 'tuple' object has no attribute 'print' - Stack Overflow
I am new in this website so sorry if I am doing something absurd or against rules but I have a question. I am new to Python and programming. I am learning Python and when I am exercising I encount... More on stackoverflow.com
🌐 stackoverflow.com
🌐
LearnDataSci
learndatasci.com › solutions › python-attributeerror-tuple-object-has-no-attribute
Python AttributeError: 'tuple' object has no attribute – LearnDataSci
The underscore conveys to readers of your code that you intend not to use the index value. The error AttributeError: 'tuple' object has no attribute is caused when treating the values within a tuple as named attributes.
🌐
GitHub
github.com › jprouty › mint-amazon-tagger › issues › 15
'AttributeError: 'tuple' object has no attribute 'format' · Issue #15 · jprouty/mint-amazon-tagger
March 23, 2018 - Pickle epoch: 1521848325 Traceback (most recent call last): File "./tagger.py", line 679, in <module> main() File "./tagger.py", line 194, in main for r in refunds] File "./tagger.py", line 194, in <listcomp> for r in refunds] File "/Users/noah/Projects/mint-amazon-tagger/amazon.py", line 529, in to_mint_transaction note = self.get_note(), File "/Users/noah/Projects/mint-amazon-tagger/amazon.py", line 514, in get_note 'Invoice url: {}').format( AttributeError: 'tuple' object has no attribute 'format' No one assigned ·
Author   noahsw
🌐
GitHub
github.com › pytorch › pytorch › issues › 116584
ERROR: AttributeError: 'tuple' object has no attribute 'to' · Issue #116584 · pytorch/pytorch
January 1, 2024 - ------------------------------... {:.6f}'.format( 17 epoch, batch_idx * len(data), len(train_loader.dataset), 18 100. * batch_idx / len(train_loader), loss.item())) 20 for epoch in range(1, 11): ---> 21 train(epoch) Cell In[118], line 10, in train(epoch) 8 model.train() 9 for batch_idx, (data, target) in enumerate(train_loader): ---> 10 data, target = data.to(device), target.to(device) 11 optimizer.zero_grad() 12 output = model(data) AttributeError: 'tuple' object has no attribute ...
Author   andysingal
🌐
Linux Manual Page
linux.die.net › diveintopython › html › native_data_types › tuples.html
3.3. Introducing Tuples
A tuple can not be changed in any way once it is created. >>> t = ("a", "b", "mpilgrim", "z", "example") >>> t ('a', 'b', 'mpilgrim', 'z', 'example') >>> t[0] 'a' >>> t[-1] 'example' >>> t[1:3] ('b', 'mpilgrim') >>> t ('a', 'b', 'mpilgrim', 'z', 'example') >>> t.append("new") Traceback (innermost last): File "<interactive input>", line 1, in ? AttributeError: 'tuple' object has no attribute 'append' >>> t.remove("z") Traceback (innermost last): File "<interactive input>", line 1, in ?
Find elsewhere
🌐
Autodesk
download.autodesk.com › global › docs › softimage2014 › en_us › sdkguide › files › script_trouble_ERRORtupleqobjecthasnoattribute.htm
ERROR : 'tuple' object has no attribute
# ERROR : Traceback (most recent call last): # File "<Script Block >", line 14, in ? # app.LogMessage( "old source: " + prevsrc.FullName ) # AttributeError: 'tuple' object has no attribute 'FullName' # - [line 14]
🌐
PyTorch Forums
discuss.pytorch.org › vision
'tuple' object has no attribute 'to' in pytorch - vision - PyTorch Forums
June 19, 2021 - I got this error while trying to test CNN model. I already checked type about this error point’variable. Here is error point 10. imgs = imgs.to(device) #imgs type <class ‘torch.Tensor’> —> 11 …
Top answer
1 of 2
2

You need to create instances of your class:

Enemies = []

i = 0
while (i < 9):
    randomhealth = random.randrange(125,300,25)
    randomdamage = random.randrange(25,100,25)
    randomammo = random.randrange(20,200,20)

    # create an Enemy - not a tuple of values
    new_enemy = Enemy( "Enemy {}".format(i), randomhealth, randomdamage, randomammo)
    Enemies.append(new_enemy)

    i += 1

for Enemy in Enemies:
    Enemy.properties()

If you create a __str__(self) method in your class you can "tell" python how to print an instance of your class:

class Enemy:
    # snipped what you already had

    # is used if you print(instance)
    def __str__(self):
        return  """Properties:
Name: {}
Health: {}
Damage: {}
Ammo:   {}""".format(self.name, self.health, self.damage, self.ammo)

    # is used by lists if you print a whole list
    def __repr__(self):
        return str(self)

Read about __str__ here: python __str__ for an object

2 of 2
0

Okay, first off, don't do shenanigans like

i = 0
while (i < 9):
    i++
    // bad

use

for i in range(9):
   // good

instead.

Second off, with

new_enemy = ("Enemy" + str(i+1),randomhealth,randomdamage,randomammo)
Enemies.append(new_enemy)

you're appending a Tuple to your Entities list. How could you possibly expect that Tuple to have the properties of your Entity class?

So what you want to use instead is

Enemies = []

for i in range(9):
    randomhealth = random.randrange(125,300,25)
    randomdamage = random.randrange(25,100,25)
    randomammo = random.randrange(20,200,20)
    new_enemy = Enemy("Enemy" + str(i+1), randomhealth, randomdamage, randomammo)
    Enemies.append(new_enemy)

for Enemy in Enemies:
    Enemy.print()

Next, in your last for loop, you're using the class name Enemy as a variable in the loop. Terrible idea, but luckily you can just make that lowercase. So, why does it STILL say that your Enemy class has no print member? Because you haven't defined one, you called the method "properties" instead.

for enemy in Enemies:
    enemy.properties()

And it works. However, since we're in python, we can simplify this code quite a lot.

Endresult:

import random


class Enemy:

    def __init__(self,name,health,damage,ammo):
        self.name = name
        self.health = health
        self.damage = damage
        self.ammo = ammo

    def __str__(self):
        return "Properties:\nName: {}\nHealth: {}\nDamage: {}\nAmmo: {}".format(
            self.name, self.health, self.damage, self.ammo)

    #your other methods

Enemies = [Enemy(name="Enemy" + str(i),
                 health=random.randrange(125, 300, 25),
                 damage=random.randrange(25, 100, 25),
                 ammo=random.randrange(20, 200, 20))
           for i in range(1, 10)]

for enemy in Enemies:
    print(enemy)
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-tuple-object-has-no-attribute
AttributeError: 'tuple' object has no attribute X in Python | bobbyhadz
April 8, 2024 - The Python AttributeError: 'tuple' object has no attribute occurs when we access an attribute that doesn't exist on a tuple.
🌐
PyTorch Forums
discuss.pytorch.org › nlp
AttributeError: 'tuple' object has no attribute 'repeat' - nlp - PyTorch Forums
January 9, 2022 - I am doing an assignment on Neural Machine Translation and training an LSTM specifically . During Decoding stage I got this Error " AttributeError: ‘tuple’ object has no attribute ‘repeat’ ". I am unable to understand wh…
🌐
FreeDesktop
bugs.freedesktop.org › show_bug.cgi
107566 – AttributeError: 'tuple' object has no attribute 'major'
August 14, 2018 - Bugzilla – Bug 107566 AttributeError: 'tuple' object has no attribute 'major' Last modified: 2018-08-14 15:53:51 UTC
🌐
Reddit
reddit.com › r/learnpython › getting attributeerror: 'tuple' object has no attribute 'items'
r/learnpython on Reddit: Getting AttributeError: 'tuple' object has no attribute 'items'
February 1, 2021 -
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?