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
🌐
GitHub
github.com › huggingface › transformers › issues › 7760
AttributeError: 'tuple' object has no attribute 'detach' · Issue #7760 · huggingface/transformers
October 13, 2020 - The script gives the error: Traceback (most recent call last): File "train.py", line 219, in <module> train_and_evaluate(model, train_data, val_data, optimizer, scheduler, params, args.model_dir, args.restore_file) File "train.py", line 106, in train_and_evaluate train_metrics = evaluate(model, train_data_iterator, params, mark='Train') File "/content/BERT-keyphrase-extraction/evaluate.py", line 54, in evaluate batch_output = batch_output.detach().cpu().numpy() AttributeError: 'tuple' object has no attribute 'detach' The model should continue training after the first epoch ·
Author   ShivanshuPurohit
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-tuple-object-has-no-attribute-detach › 129989
AttributeError: 'tuple' object has no attribute 'detach' - PyTorch Forums
August 22, 2021 - Dear all, I run the following code and it works fine. Only the visualisation (out.dteach() command in def visualize(h, color):slight_smile: does not work. #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on…
Discussions

AttributeError: 'tuple' object has no attribute '' Error Help
Remove the * in front of *arg. That is converting the argument into a tuple. More on reddit.com
🌐 r/learnpython
5
9
January 10, 2021
deep learning - how can I convert tensor shape to numpy array? - Data Science Stack Exchange
$\begingroup$ They are indeed pytorch tensors, and i did run my code in GPU. When i add .detach() i get the error 'tuple' object has no attribute 'detach'. When I add .cpu() I get 'tuple' object has no attribute 'cpu'.. Either way, thanks for your help! More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
May 2, 2021
AttributeError: 'tuple' object has no attribute 'detach'
Dear all, I run the following code and it works fine. Only the visualisation (out.dteach() command in def visualize(h, color):slight_smile: does not work. #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on… More on discuss.pytorch.org
🌐 discuss.pytorch.org
0
0
August 22, 2021
Getting AttributeError: 'tuple' object has no attribute 'items'
items() is a method specifically for dictionaries, not tuples. Tuples are like lists, except they are immutable. More on reddit.com
🌐 r/learnpython
11
1
February 1, 2021
🌐
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.
🌐
Autodesk
download.autodesk.com › global › docs › softimage2014 › en_us › sdkguide › files › script_trouble_ERRORtupleqobjecthasnoattribute.htm
ERROR : 'tuple' object has no attribute
Use the tuple-style syntax as explained in Getting Output Arguments from Methods. ... Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Find elsewhere
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-tuple-object-has-no-attribute-detach › 129989 › 3
AttributeError: 'tuple' object has no attribute 'detach' - #3 by StephDoc - PyTorch Forums
August 22, 2021 - Dear all, I run the following code and it works fine. Only the visualisation (out.dteach() command in def visualize(h, color):slight_smile: does not work. #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on…
🌐
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?

🌐
Stack Overflow
stackoverflow.com › questions › 74951234 › attributeerror-tokenclassifieroutput-object-has-no-attribute-detach
nlp - AttributeError: 'TokenClassifierOutput' object has no attribute 'detach' - Stack Overflow
December 29, 2022 - AttributeError Traceback (most recent call last) <ipython-input-49-3e5217186317> in <module> 13 logits = model(input_ids, token_type_ids=None, attention_mask=input_mask,) 14 ---> 15 logits = logits.detach().cpu().numpy() 16 logits = [list(p) for p in np.argmax(logits, axis=2)] 17 AttributeError: 'TokenClassifierOutput' object has no attribute 'detach' model.eval() y_true = [] y_pred = [] eval_loss, eval_accuracy = 0, 0 nb_eval_steps, nb_eval_examples = 0, 0 for batch in valid_dataloader: batch = tuple(t.to(device) for t in batch) input_ids, input_mask, label_ids = batch with torch.no_grad(): logits = model(input_ids, token_type_ids=None, attention_mask=input_mask,) logits = logits.detach().cpu().numpy() logits = [list(p) for p in np.argmax(logits, axis=2)] label_ids = label_ids.to('cpu').numpy() input_mask = input_mask.to('cpu').numpy()
🌐
Python.org
discuss.python.org › python help
AttributeError: 'tuple' object has no attribute 'enter' - Python Help - Discussions on Python.org
March 5, 2025 - Help! I’m coding a game program for my daughter and I come up with the following error: Traceback (most recent call last): File “/home/roberto-padilla/mystuff/ella_game.py”, line 193, in a_game.play() File “/home/roberto-padilla/mystuff/ella_game.py”, line 22, in play next_scene_name = current_scene.enter() ^^^^^^^^^^^^^^^^^^^ AttributeError: ‘tuple’ object has no attribute ‘enter’ Here’s the code: class Engine(object): def __init__(self, scene_map): self.scene_map = scen...
Top answer
1 of 4
9

In the line:

Jobs = ()

you create a tuple. A tuple is immutable and has no methods to add, remove or alter elements. You probably wanted to create a list (lists have an .append-method). To create a list use the square brackets instead of round ones:

Jobs = []

or use the list-"constructor":

Jobs = list()

However some suggestions for your code:

opening a file requires that you close it again. Otherwise Python will keep the file handle as long as it is running. To make it easier there is a context manager for this:

with open('Jobs.txt') as openFile:
    x = 1
    while x != 0:
        Stuff = openFile.readline(x)
        if Stuff != '':
            Jobs.append(Stuff)
        else:
            x = 0

As soon as the context manager finishes the file will be closed automatically, even if an exception occurs.


It's used very rarely but iter accepts two arguments. If you give it two arguments, then it will call the first each iteration and stop as soon as the second argument is encountered. That seems like a perfect fit here:

with open('Jobs.txt') as openFile:
    for Stuff in iter(openFile.readline, ''):
        Jobs.append(Stuff)

I'm not sure if that's actually working like expected because openFile.readline keeps trailing newline characters (\n) so if you want to stop at the first empty line you need for Stuff in iter(openFile.readline, '\n'). (Could also be a windows thingy on my computer, ignore this if you don't have problems!)


This can also be done in two lines, without creating the Jobs before you start the loop:

with open('Jobs.txt') as openFile:
    # you could also use "tuple" instead of "list" here.
    Jobs = list(iter(openFile.readline, ''))  

Besides iter with two arguments you could also use itertools.takewhile:

import itertools
with open('Jobs.txt') as openFile:
    Jobs = list(itertools.takewhile(lambda x: x != '', openFile))

The lambda is a bit slow, if you need it faster you could also use ''.__ne__ or bool (the latter one works because an empty string is considered False):

import itertools
with open('Jobs.txt') as openFile:
    Jobs = list(itertools.takewhile(''.__ne__, openFile))
2 of 4
0

The Jobs object you created is a tuple, which is immutable. Therefore, you cannot "append" anything to it.

Try

Jobs = []

instead, in which you create a list object.

🌐
GitHub
github.com › daniilidis-group › neural_renderer › issues › 46
Bug: render function returns a tuple not a tensor · Issue #46 · daniilidis-group/neural_renderer
April 9, 2019 - Bug: render function returns a tuple not a tensor#46 · Copy link · gsygsy96 · opened · on Apr 9, 2019 · When I run exampe2.py, an error are reported: Traceback (most recent call last): File "./examples/example2.py", line 100, in <module> main() File "./examples/example2.py", line 94, in main image = images.detach().cpu().numpy()[0].transpose((1, 2, 0)) AttributeError: 'tuple' object has no attribute 'detach' So, I scan the render code, and find that it returns a tuple.
🌐
Python Forum
python-forum.io › thread-13250.html
Tuple no attribute error
Linux Mint 18.2 Python 3.5. Am old time BASIC person. Help. Have no understanding how to deal with this. An example please. #!/usr/bin/python3 # with open( 'expenses-18', 'r') as yrs_file: for line in enumerate(yrs_file): (pdate,ca...
🌐
Free Python Source Code
freepythonsourcecode.com › post › 116
'tuple' object has no attribute 'json' and AttributeError
September 29, 2024 - To Fix AttributeError: 'tuple' object has no attribute 'remove' Python: Convert the tuple to a list before using remove, and then convert it back if necessary.
🌐
Reddit
reddit.com › r/learnpython › ‘tuple’ object has no attribute ‘append’
r/learnpython on Reddit: ‘tuple’ object has no attribute ‘append’
September 29, 2021 -

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??

🌐
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.
🌐
Google AI
discuss.ai.google.dev › tensorflow › general discussion
layers.Dense - AttributeError: 'tuple' object has no attribute 'rank' " - General Discussion - Google AI Developers Forum
June 3, 2024 - I am getting the error "AttributeError: ‘tuple’ object has no attribute ‘rank’ " on the line : dense = layers.Dense(4, activation=act_func)(inputs), in the following function : def gen_model(act_func = ‘relu’): input…