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))
Answer from MSeifert on Stack Overflow
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.

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

Discussions

AttributeError: 'tuple' object has no attribute 'append'
Tuples in Python are immutable, i.e., they can’t be changed (and therefore appended to) like lists can. That’s why you’re getting the error that you have · It looks like the example code you’re using has become deprecated since plotly 3.0 has switched to representing Figure.data as ... More on community.plotly.com
🌐 community.plotly.com
3
0
July 16, 2018
python - Flask self.errors.append() - AttributeError: 'tuple' object has no attribute 'append' - Stack Overflow
My small registration app gives and error when I try to validate the submited data by user and check if the entered e-mail exists. here is my files: forms: from flask.ext.wtf import Form from w... More on stackoverflow.com
🌐 stackoverflow.com
In unit tests, specifying the `--target-version` flag raises `AttributeError: 'tuple' object has no attribute 'append'`.
Describe the bug In unit tests, specifying the --target-version flag raises AttributeError: 'tuple' object has no attribute 'append'. To Reproduce Just add # flags: --target-version... More on github.com
🌐 github.com
0
July 31, 2025
python - What does AttributeError: 'tuple' object has no attribute 'append' and how do I fix my code? - Stack Overflow
It keeps saying that line 5 (contents.append(data)) has a AttributeError: 'tuple' object has no attribute 'append'...if just not sure what it means or how to fix it. Any help/resources would be greatly appreciated. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Sololearn
sololearn.com › en › Discuss › 513598 › attributeerror-tuple-object-has-no-attribute-append
AttributeError: 'tuple' object has no attribute 'append' | Sololearn: Learn to code for FREE!
age(23,43,25,53,22) age.append(100) print(age) I tried to run the above code on JetBeans but error occurred. AttributeError: 'tuple' object has no attribute 'append'
🌐
Plotly
community.plotly.com › 📊 plotly python
AttributeError: 'tuple' object has no attribute 'append' - 📊 Plotly Python - Plotly Community Forum
July 16, 2018 - Tuples in Python are immutable, i.e., they can’t be changed (and therefore appended to) like lists can. That’s why you’re getting the error that you have · It looks like the example code you’re using has become deprecated since plotly 3.0 has switched to representing Figure.data as ...
🌐
W3Schools
w3schools.com › python › trypython.asp
W3Schools online PYTHON editor
Traceback (most recent call last): File "./prog.py", line 2, in <module> AttributeError: 'tuple' object has no attribute 'append'
Find elsewhere
🌐
GitHub
github.com › psf › black › issues › 4721
In unit tests, specifying the `--target-version` flag raises `AttributeError: 'tuple' object has no attribute 'append'`. · Issue #4721 · psf/black
July 31, 2025 - When the flag is used, it attempts to call .append() on the tuple, leading to an AttributeError. ... parser.add_argument( "--target-version", action="store", type=lambda val: (TargetVersion[val.upper()],), default=(), ) Alternatively, setting default=[] would also work with action="append".
Author   ranjodhsingh1729
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
1451804 – "AttributeError: 'tuple' object has no attribute 'append'" error observed during ipa upgrade with latest package.
RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
🌐
Codecademy Forums
discuss.codecademy.com › data science
AttributeError: 'tuple' object has no attribute 'append' - Data Science - Codecademy Forums
January 31, 2024 - Hello I’m working on the Frida Kahlo off platform project i’m stuck on task number four and keep getting this error. I’m not sure what i’m doing wrong in order to get this message. I have tried to fix it and look it up, any help would be great! Here’s my code… paintings = ‘The Two Fridas’, ‘My Dress Hangs Here’, ‘Tree of Hope’, ‘Self Portrait With Monkeys’ dates = 1939, 1933, 1946, 1940 #Zipping paintings and dates into an object. paintings = list(zip(paintings,dates)) print(paintings) Ad...
🌐
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 'append'" occurs when we try to call the append() method on a tuple instead of a list.
🌐
GitHub
github.com › AndreasHeger › CGATReport › issues › 25
AttributeError: 'tuple' object has no attribute 'append' · Issue #25 · AndreasHeger/CGATReport
November 1, 2016 - I'm getting this error on running one of my trackers: Traceback (most recent call last): File "/ifs/devel/Ian/python/bin/cgatreport-test", line 9, in load_entry_point(&...
Author   IanSudbery
🌐
YouTube
youtube.com › jakubication
AttributeError: 'tuple' object has no attribute 'append' - YouTube
To correct the Python AttributeError: 'tuple' object has no attribute 'append', you need to modify your code so that it properly adds an element to the end o...
Published   October 14, 2024
🌐
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.
🌐
Sololearn
sololearn.com › en › Discuss › 2745324 › python-attributeerror-tuple-object-has-no-attribute-append
Python AttributeError: 'tuple' object has no attribute 'append' | Sololearn: Learn to code for FREE!
last_semester_gradebook = [["politics", 80], ["latin", 96], ["dance", 97], ["architecture", 65]] # Your code below: subjects = ["physics", "calculus", "poetry", "history"] gardes = [98, 97, 85, 88] gradebook = [["physics", 98], ["calculus", 97], ["poetry", 85]], ["history", 88] print(gradebook) gradebook.append(["computer science", 100]) ... gradebook = [ ["physics", 98], ["calculus", 97], ["poetry", 85], ["history", 88] ] Misplaced of ']' in the definition of <gradebook> list. ... My guess is try using a list instead of a tuple.
🌐
Free Python Source Code
freepythonsourcecode.com › post › 117
With Examples Fix attributeerror: 'tuple' object has no attribute ...
September 29, 2024 - x, y = zip((1, 2), (3, 4)) print(x.items()) # AttributeError: 'tuple' object has no attribute 'items' ... Review how you assign or return values if you accidentally create a tuple when you mean to make something else. data = "Hello", # This creates a tuple with one element: ('Hello',) print(type(data)) ... Convert the tuple to a list if you need to perform list-like operations (such as appending or extending).
🌐
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 ...