import os from PyQt.QtCore import QTemporaryFile # create temporary file temp = QTemporaryFile() if temp.open(): # write to file temp.write(b"Hello world!") print("Data written to temporary file:", temp.fileName()) # automatic deletion of temporary file del temp
import os from qgis.core import QgsVectorLayer from PyQt.QtCore import QTemporaryFile # create temporary file temp = QTemporaryFile() if temp.open(): # write to file temp.write(b"ID,NAME\n1,New York\n2,Los Angeles") print("Data written to temporary file:", temp.fileName()) # create layer from temporary file layer = QgsVectorLayer("{}|layername=MyLayer|fid=ID".format(temp.fileName()), "My Layer", "delimitedtext") if not layer.isValid(): print("Layer failed to load") # automatic deletion of temporary file del tempPackages/Libraries: PyQt, QGIS Core.