Python Forum
Fastest Way of Writing/Reading Data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fastest Way of Writing/Reading Data
#2
you can use a flat file for storage, open using mode 'w+', ('a+' if you wish to keep old contents) and after each write make a call to flush()

example -- something like this (won't run as written, but syntax is there):
import os
from pathlib import Path

# following assures starting directory same as script.
os.chdir(os.path.abspath(os.path.dirname(__file__)))

# create ref to script directory
homepath = Path('.')

# Here, create a subdirectory to hold output data (move this to wherever you wish)
# if paths exists, do nothing. If not create them
OutDatapath = homepath / 'data_out'
OutDatapath.mkdir(exist_ok=True)

outfile = OutDatapath / 'MyData.txt' # Rename this as you wish

with outfile.open('w+') as fp:
    # ... your code here
    fp.write(scraped_data)
    fp.flush()
since the file is flushed each time written, it can be opened for read by another program, and get all data up to the last write.
Reply


Messages In This Thread
Fastest Way of Writing/Reading Data - by JamesA - Jul-27-2021, 10:17 AM
RE: Fastest Way of Writing/Reading Data - by Larz60+ - Jul-27-2021, 03:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 265 Apr-18-2024, 09:55 PM
Last Post: deanhystad
  Fastest way tkinter Quatrixouuu 2 406 Feb-19-2024, 07:20 AM
Last Post: Danishhafeez
  What is the fastest way to get all the frames from a video file? glorsh66 3 1,084 May-26-2023, 04:41 AM
Last Post: Gribouillis
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,050 Dec-06-2022, 11:09 AM
Last Post: mg24
  Reading All The RAW Data Inside a PDF NBAComputerMan 4 1,350 Nov-30-2022, 10:54 PM
Last Post: Larz60+
  Create a function for writing to SQL data to csv mg24 4 1,154 Oct-01-2022, 04:30 AM
Last Post: mg24
  Reading Data from JSON tpolim008 2 1,084 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Need Help writing data into Excel format ajitnayak87 8 2,515 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
  Help reading data from serial RS485 korenron 8 13,994 Nov-14-2021, 06:49 AM
Last Post: korenron
  Help with WebSocket reading data from anoter function korenron 0 1,337 Sep-19-2021, 11:08 AM
Last Post: korenron

Forum Jump:

User Panel Messages

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