[Python] I'm not sure why the file won't write to, and other problems with basic code [closed]

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    So this program is for an assignment, and honestly I'm not good at Python in the slightest. This program is intended to read a file that has been inputted, read the DNA sequence(s) provided in each line, and then create a new text file with a summary of what was found. [This is what an output file should generally look like when complete.][1]

    However, I'm getting an error that says

    File c:\users\super\.spyder-py3\program4.py:53
    51 outputfile = input("Choose the name for your file:")
    52 with open(outputfile, "w") as file:
    ---> 53 outputfile.write("FRAGMENT GC RATIO COMMENTS\n")
    54 outputfile.write("\n")
    55 outputfile.write(dnaFragment, gcratio, comment, "\n")

    AttributeError: 'str' object has no attribute 'write'"```

    I have attached my entire code and the error message in the image links below. If there's anything else that needs fixing, please let me know.
    [Link 1][2]
    [Link 2][3]


    [1]: https://i.sstatic.net/51tYcgnH.png
    [2]: https://i.sstatic.net/JphZuFb2.png
    [3]: https://i.sstatic.net/M3Wn2jpB.png

    Continue reading...

Compartilhe esta Página