Python Forum
save content of table into file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
save content of table into file
#4
Is there a reason you open file with "a+" if you only want to write to it?
To write to the dir where the .py file was started use first line.
To handle reading/writing files use "with" command.
To create output to write to file use f-strings (available since Python 3.6)
local_dir = os.path.dirname(__file__)
with open(os.path.join(local_dir, "guru99.txt"), "w") as file:
    for data in listeTableLoc35R:
        file.write(f'{data[0]}\n')
Reply


Messages In This Thread
save content of table into file - by atlass218 - Aug-20-2019, 09:13 AM
RE: save content of table into file - by atlass218 - Aug-21-2019, 10:39 AM
RE: save content of table into file - by ThomasL - Aug-21-2019, 11:26 AM
RE: save content of table into file - by atlass218 - Aug-22-2019, 02:47 PM
RE: save content of table into file - by atlass218 - Aug-23-2019, 12:12 PM
RE: save content of table into file - by SheeppOSU - Aug-23-2019, 01:06 PM
RE: save content of table into file - by atlass218 - Aug-23-2019, 03:01 PM
RE: save content of table into file - by atlass218 - Aug-26-2019, 10:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy xml content from webpage and save to locally without special characters Nik1811 14 1,080 Mar-26-2024, 09:28 AM
Last Post: Nik1811
  Open/save file on Android frohr 0 363 Jan-24-2024, 06:28 PM
Last Post: frohr
  how to save to multiple locations during save cubangt 1 592 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  save values permanently in python (perhaps not in a text file)? flash77 8 1,284 Jul-07-2023, 05:44 PM
Last Post: flash77
  Save and Close Excel File avd88 0 3,167 Feb-20-2023, 07:19 PM
Last Post: avd88
  Save multiple Parts of Bytearray to File ? lastyle 1 984 Dec-10-2022, 08:09 AM
Last Post: Gribouillis
  Use module docx to get text from a file with a table Pedroski55 8 6,356 Aug-30-2022, 10:52 PM
Last Post: Pedroski55
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,125 Mar-28-2022, 03:38 PM
Last Post: snippsat
Sad Want to Save Print output in csv file Rasedul 5 11,133 Jan-11-2022, 07:04 PM
Last Post: snippsat
Thumbs Up Parsing a YAML file without changing the string content..?, Flask - solved. SpongeB0B 2 2,323 Aug-05-2021, 08:02 AM
Last Post: SpongeB0B

Forum Jump:

User Panel Messages

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