Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unexpected object?
#1
name = input("Your name, plz:")
file = "temp.txt"
with open(file, "w") as file:
    file.write(name + "\n")

file = "temp.txt"
while True:
    name = input("Your name, again:")
    if name == "":
        break
    else:
        with open(file, "a") as file:
            file.write(name + "\n")
When I input 3 names and it went wrong:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-44303ce02481> in <module>
10 break
11 else:
---> 12 with open(file, "a") as file:
13 file.write(name + "\n")

TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
---------------------------------------------------------------------------

But I really don't know where the syntax error is...
Does anyone help me solve this issue? Thank you very much.
Reply


Messages In This Thread
unexpected object? - by urufu - Mar-08-2020, 02:06 PM
RE: unexpected object? - by snippsat - Mar-08-2020, 02:29 PM
RE: unexpected object? - by urufu - Mar-08-2020, 02:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting an unexpected generator object ? mcgrim 19 7,369 Mar-29-2019, 11:35 AM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020