You're missing the open.

openfile = open('test.txt','w')

And at the end there are missing parens when you try to close the file

openfile.close()

Edit: I just saw another problem.

openfile.write(str(cost)+'\n')
Answer from Matthias on Stack Overflow
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
AttributeError: 'tuple' object has no attribute 'enter'
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/r… More on discuss.python.org
🌐 discuss.python.org
2
0
March 5, 2025
python - How to fix "tuple object has no attribute"? - Stack Overflow
I'm doing a homework problem, and I keep getting an error that the tuple in the __init__ function has no age attribute, but it does. I've tried using the x[y] notation to try and solve this, but n... More on stackoverflow.com
🌐 stackoverflow.com
opencv - AttributeError: 'tuple' object has no attribute 'write' , instance segmentation python - Stack Overflow
I have used code of this blog "https://learnopencv.com/deep-learning-based-object-detection-and-instance-segmentation-using-mask-r-cnn-in-opencv-python-c/" Titled Deep learning based Object 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
As mentioned previously, any function which returns multiple values will output them as a tuple-type by default, which cannot be dot-accessed. To demonstrate this, let's write a small function called perform_calculations that takes two numbers and outputs values for their sum, product, and quotient:
🌐
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.
🌐
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...
Find elsewhere
🌐
Free Python Source Code
freepythonsourcecode.com › post › 117
With Examples Fix attributeerror: 'tuple' object has no attribute ...
September 29, 2024 - Tuples don't have attributes like objects. Instead, you access their elements by index. person = ("Ashirafu", "Kibalama", 34) # Trying to access attributes directly will raise an AttributeError print(person.first_name) # AttributeError: 'tuple' object has no attribute 'first_name'
🌐
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...
🌐
GitHub
github.com › ultralytics › yolov5 › issues › 13213
AttributeError: 'tuple' object has no attribute 'to' · Issue #13213 · ultralytics/yolov5
July 24, 2024 - File "export.py", line 1346, in run model = attempt_load(weights, device=device, inplace=True, fuse=True) # load FP32 model File "/home/mi/PycharmProjects/yolov5/models/experimental.py", line 99, in attempt_load ckpt = (ckpt.get("ema") or ckpt["model"]).to(device).float() # FP32 model AttributeError: 'tuple' object has no attribute 'to'
Author   stillbetter
🌐
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 …
🌐
Databricks
kb.databricks.com › python › python-exec-display-cancelled
Python command execution fails with AttributeError - Databricks
May 19, 2022 - This article can help you resolve scenarios in which Python command execution fails with an AttributeError. Problem: 'tuple' object has no attribute 'type'
🌐
Autodesk
download.autodesk.com › global › docs › softimage2014 › en_us › sdkguide › files › script_trouble_ERRORtupleqobjecthasnoattribute.htm
ERROR : 'tuple' object has no attribute
In this case, ConnectFromFile returns both the new shader source and provides the old disconnected shader in the PrevDataSource output argument, so the myvar variable is being interpreted as a tuple by Python.
🌐
GitHub
github.com › hwchase17 › langchain › issues › 7518
AttributeError: 'tuple' object has no attribute 'page_content' · Issue #7518 · langchain-ai/langchain
July 11, 2023 - df = loadSqlData() df.to_csv('profiles.csv', index=False) # Iterate through DataFrame rows # Time Complexity: O(n), where n is the number of rows in the DataFrame for _, record in df.iterrows(): start_time = time.time() # Get metadata for this record # Time Complexity: O(1) metadata = { 'IdentityId': str(record['IdentityId']) } st.write(f'Time taken for metadata extraction: {time.time() - start_time} seconds') start_time = time.time() # Split record text into chunks # Time Complexity: O(m), where m is the size of the text record_texts = text_splitter.split_text(record['content']) st.write(f'Ti
Author   levalencia
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-attributeerror-object-has-no-attribute
How to fix AttributeError: object has no attribute - GeeksforGeeks
July 23, 2025 - It typically consists of two parts: "AttributeError" and "Object has no attribute." The former indicates the type of error, and the latter suggests that the attribute we are trying to access does not exist for the object.