You want f.write, not outfile.write...

outfile is the name of the file as a string. f is the file object.

As noted in the comments, file.write expects a string, not a sequence. If you wanted to write data from a sequence, you could use file.writelines. e.g. f.writelines(self._headers). But beware, this doesn't append a newline to each line. You need to do that yourself. :)

Answer from mgilson on Stack Overflow
🌐
GitHub
github.com › dimatura › binvox-rw-py › issues › 6
AttributeError: 'str' object has no attribute 'write' · Issue #6 · dimatura/binvox-rw-py
December 22, 2018 - Hi, I modified some codes in 'write' of binvox_rw.py to resolve the error - 'AttributeError: 'str' object has no attribute 'write' , when executing the command - model.write('dilated.binvox'). Hope it helps. def write(voxel_model, fp): "...
Author   tangaggie
Discussions

AttributeError: 'str' object has no attribute 'write'
Traceback (most recent call last): ...thon3.8/site-packages/PythonSed/sed.py", line 139, in printline print(line, file=self.output) AttributeError: 'str' object has no attribute 'write'... More on github.com
🌐 github.com
2
March 22, 2020
How do i fix this : AttributeError: 'str' object has no attribute 'current'
It says AttributeError: 'str' object has no attribute 'current'. That error isn't coming from this function. More on reddit.com
🌐 r/learnpython
11
0
December 7, 2023
stream.write(msg + self.terminator) AttributeError: 'str' object has no attribute 'write'
I'm getting this error while trying to log some informations : -- Logging error --- Traceback (most recent call last): File "/home/yf/miniconda3/envs/grafenv/lib/python3.9/logging/init.py", line 10... More on github.com
🌐 github.com
2
August 10, 2022
AttributeError: 'str' object has no attribute 'write' - Post.Byes
OS is Ubuntu Linux 9.10/Python Version is 2.6.4/Gui Tool is Dr. Python My program has a large html-coded string called tarr_record. When I try to open an output file and write the record to the file, I receive the following error: AttributeError: 'str' object has no attribute 'write' ... More on post.bytes.com
🌐 post.bytes.com
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: str object has no attribute write [solved]
Attributeerror: str object has no attribute write [SOLVED]
March 21, 2023 - When you run this code, it will create a new file called “my_file.txt” and write the string “Hi, Welcome to ITSOURCECODE” to it. There will be no error message because we are using the write method on a file object, which does have this method. Attributeerror: module ‘jinja2’ has no attribute ‘contextfilter’
🌐
Google Groups
groups.google.com › g › django-users › c › 0khPGARBtZo
'str' object has no attribute 'write'
In the first line there, you're setting "output" (which used to be a file object) to a string, and then in the next line you're trying to call the "write" method again (which would work if it were still a file object, but it's not anymore).
🌐
GitHub
github.com › GillesArcas › PythonSed › issues › 5
AttributeError: 'str' object has no attribute 'write' · Issue #5 · GillesArcas/PythonSed
March 22, 2020 - Traceback (most recent call last): ...thon3.8/site-packages/PythonSed/sed.py", line 139, in printline print(line, file=self.output) AttributeError: 'str' object has no attribute 'write'...
Author   bionade24
🌐
Reddit
reddit.com › r/learnpython › how do i fix this : attributeerror: 'str' object has no attribute 'current'
r/learnpython on Reddit: How do i fix this : AttributeError: 'str' object has no attribute 'current'
December 7, 2023 -

There is something wrong with this function. It shows no errors, but when I try to run it, It says AttributeError: 'str' object has no attribute 'current'. (BTW, i am trying to run it as a flet on spyder)

def leapyears(e):

days_in_month = {1: 31, 3: 31, 4: 30, 5:31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31 }

month = int(EnterMonth_text.value)

year = int(EnterYear_text.value)

if year % 100 == 0:

if year % 400 == 0:

leap_year = True

elif year % 4 == 0:

leap_year = True

else:

leap_year = False

if month == 2 :

if leap_year:

days_in_month[2] = 29

else:

days_in_month[2]= 28

output_textfield.value= days_in_month[month]

page.update()

🌐
GitHub
github.com › python › cpython › issues › 95850
stream.write(msg + self.terminator) AttributeError: 'str' object has no attribute 'write' · Issue #95850 · python/cpython
August 10, 2022 - -- Logging error --- Traceback (most recent call last): File "/home/yf/miniconda3/envs/grafenv/lib/python3.9/logging/init.py", line 1086, in emit stream.write(msg + self.terminator) AttributeError: 'str' object has no attribute 'write' This is my logging_conf.ini: [loggers] keys=root ·
Author   youssefbenfarhat
Find elsewhere
🌐
Post.Byes
post.bytes.com › home › forum › topic › python
AttributeError: 'str' object has no attribute 'write' - Post.Byes
Python My program has a large html-coded string called tarr_record. When I try to open an output file and write the record to the file, I receive the following error: AttributeError: 'str' object has no attribute 'write' [CODE=Python] open(output_fil e, "a") output_file.wri te(tarr_record + "\n") output_file.clo se() [/CODE]
🌐
Researchdatapod
researchdatapod.com › home › how to solve python attributeerror: ‘str’ object has no attribute ‘write’
How to Solve Python AttributeError: 'str' object has no attribute 'write' - The Research Scientist Pod
March 19, 2022 - If we want to write to a file, we have to call the File method write() on the file object with the text to write as the argument. If we try to call the write() method on the text we want to write to file, we will get the AttributeError: ‘str’ object has no attribute ‘write’.
🌐
Stack Overflow
stackoverflow.com › questions › 42294279 › attributeerror-str-object-has-no-attribute-write
python 3.x - AttributeError: 'str' object has no attribute 'write' - Stack Overflow
myFile = ("cat2numbers.txt") with open("cat2numbers.txt", "wt") as f: print("Writing to the file: ", myFile) # Telling the user what file they will be writing to for i in range(9): sentence = input("Please enter a sentence without punctuation ").lower() # Asking the user to enter a sentence words = sentence.split() # Splitting the sentence into single words positions = [words.index(word) + 1 for word in words] f.write(", ".join(map(str, positions))) # write the places to myFile myFile.write("\n") print("The positions are now in the file")
🌐
Reddit
reddit.com › r/learnpython › 'str' object has no attribute error?
r/learnpython on Reddit: 'Str' object has no attribute error?
November 9, 2023 -

I have some experience with programming in Java, C++, etc. and I am trying to write a simple "To-Do List" program to get used to Python. I'm running into the error: str object has no attribute "completed" when trying to iterate over the list of tasks, check their completion status, and display them.

Here are some relevant pieces of the program:

Constructor for the Task class

def __init__(self, task_name):

self.task_name = task_name

self.completed = False

In the ToDoList class (which holds a list of the task instances created by the user) this is the iteration throwing the error in question:

for idx, task in enumerate(self.tasks, start=1):

status = "Completed" if task.completed else "Incomplete"

print(f"{idx}. {task.task_name} - {status}")

I thought, potentially the problem lies in the fact that the enumerate function is grabbing the string value of the task instance, rather than the object itself, so maybe I can iterate over it the old fashioned way and get around it. So I tried it like this:

counter = 1

for task in self.tasks:

status = "Completed" if task.completed else "Incomplete"

print(f"{counter}. {task.task_name} - {status}")

counter += 1

Yet, it throws the same error. I know there is something I am missing or not understanding correctly here. What is it?

Thanks!

🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-str-object-has-no-attribute
AttributeError: 'str' object has no attribute 'X in Python | bobbyhadz
April 8, 2024 - If you try to access any attribute that is not in this list, you will get the "AttributeError: str object has no attribute error". Since the str object doesn't implement a write() method, the error is caused.
🌐
Brainly
brainly.com › engineering › college › what does "str object has no attribute" mean in python?
[FREE] What does "str object has no attribute" mean in Python? - brainly.com
In Python, the error message "AttributeError: 'str' object has no attribute" indicates that you are trying to access a method or attribute that does not exist for string objects.
🌐
GitHub
github.com › pallets › flask › issues › 2008
AttributeError: 'str' object has no attribute 'write' during unhandled exception logging · Issue #2008 · pallets/flask
September 6, 2016 - Flask + Zappa users are complaining about an error stemming from Flask's logging of exceptions. We can reproduce this by generating an unhandled exception in a Flask application that breaks our handler's behavior, but which works for oth...
Published   Sep 06, 2016
🌐
Apache
lists.apache.org › thread › 5y7jyfqo1gwwdc84p9xyfkpwjgbbgt7x
AttributeError: 'str' object has no attribute 'write'
Email display mode: · Modern rendering · Legacy rendering · This site requires JavaScript enabled. Please enable it
🌐
Quora
quora.com › What-can-I-do-if-I-have-attribute-error-str-object-has-no-attribute-re
What can I do if I have attribute error: 'str' object has no attribute 're'? - Quora
Answer: Work out what object should have that re attribute and why your code is using a string not the correct object. In my experience these type of errors tend to happen because of misleading variable names: if your variables are all using single letter etc. It is easy to get confused as to wh...