below is a Stata-Python interface question.
I need to write to a file opened in Stata from a Python procedure (executed from within Stata). My output is interleaved between various Stata and Python procedures.
I understand that I can close the file after each write, and then open it for appending, but I would like to avoid the associated performance penalty, and more importantly, leaving a half-produced file in a closed state. So I would like to retain the handler open in Stata and just write to the file from Python reusing the same handler until the program succeeds.
I couldn't locate the necessary output procedure in the Stata’s Python API documentation.
My preference would be of course to have the file handler accessible from Python for read/write commands as outlined here:
https://www.geeksforgeeks.org/readin...-files-python/
But if there are mirroring commands available through some utility class, a la
Code:
StataFile.Files(handle).Write("")
Is there any possibility to do it?
Alternatively, and perhaps easier to establish, is it safe (in a sense of multithreaded access, buffering, OS permissions, etc) to re-open for writing in python the same file that has been already open for writing in the same Stata session?
Thank you, Sergiy Radyakin
0 Response to 🐍 Python: write to text file
Post a Comment