Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
append my results to a file
#2
use mode 'a' to append to a file.
you should use the with construct as then you don't have to close the file, it's done automatically at end of operation (you actually forgot to close file in above example).
It's syntax is:
with open(filename, mode) as name:
    for line in name.readlines():
        ...
output can be written as part of same statement:
with open(path_input, 'r') as f_in, open(outname, 'a') as f_out:
    ...
Reply


Messages In This Thread
append my results to a file - by clarablanes - Nov-23-2018, 09:40 AM
RE: append my results to a file - by Larz60+ - Nov-23-2018, 10:23 AM
RE: append my results to a file - by Gribouillis - Nov-23-2018, 11:01 AM
RE: append my results to a file - by clarablanes - Nov-23-2018, 03:15 PM
RE: append my results to a file - by Larz60+ - Nov-23-2018, 05:07 PM
RE: append my results to a file - by clarablanes - Nov-23-2018, 06:45 PM
RE: append my results to a file - by Gribouillis - Nov-23-2018, 07:06 PM
RE: append my results to a file - by clarablanes - Nov-23-2018, 09:47 PM
RE: append my results to a file - by Gribouillis - Nov-23-2018, 10:17 PM
RE: append my results to a file - by clarablanes - Nov-23-2018, 10:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating sharepoint excel file odd results cubangt 1 1,054 Nov-03-2023, 05:13 PM
Last Post: noisefloor
Question How to append integers from file to list? Milan 8 1,694 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  Trying to send file to printer with no results. chob_thomas 2 3,657 Dec-21-2022, 07:12 AM
Last Post: Pedroski55
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,597 Sep-27-2022, 01:38 PM
Last Post: buran
  read a text file, find all integers, append to list oldtrafford 12 4,170 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,328 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  [split] Results of this program in an excel file eisamabodian 1 1,693 Feb-11-2022, 03:18 PM
Last Post: snippsat
  How to save some results in .txt file with Python? Melcu54 4 7,624 May-26-2021, 08:15 AM
Last Post: snippsat
  Running A Parser In VSCode - And Write The Results Into A Csv-File apollo 5 4,916 Jan-14-2021, 08:58 PM
Last Post: snippsat
  Writing unit test results into a text file ateestructural 3 5,008 Nov-15-2020, 05:41 PM
Last Post: ateestructural

Forum Jump:

User Panel Messages

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