7.5.1 File Objects

PyFileObject
This subtype of PyObject represents a Python file object.

PyTypeObject PyFile_Type
This instance of PyTypeObject represents the Python file type.

int PyFile_Check (PyObject *p)
Returns true if its argument is a PyFileObject.

PyObject* PyFile_FromString (char *name, char *mode)
Creates a new PyFileObject pointing to the file specified in name with the mode specified in mode.

PyObject* PyFile_FromFile (FILE *fp, char *name, char *mode, int (*close))
Creates a new PyFileObject from the already-open fp. The function close will be called when the file should be closed.

FILE * PyFile_AsFile (PyFileObject *p)
Returns the file object associated with p as a FILE *.

PyObject* PyFile_GetLine (PyObject *p, int n)
undocumented as yet

PyObject* PyFile_Name (PyObject *p)
Returns the name of the file specified by p as a PyStringObject.

void PyFile_SetBufSize (PyFileObject *p, int n)
Available on systems with setvbuf() only. This should only be called immediately after file object creation.

int PyFile_SoftSpace (PyFileObject *p, int newflag)
Sets the softspace attribute of p to newflag. Returns the previous value. This function clears any errors, and will return 0 as the previous value if the attribute either does not exist or if there were errors in retrieving it. There is no way to detect errors from this function, but doing so should not be needed.

int PyFile_WriteObject (PyObject *obj, PyFileObject *p, int flags)
Writes object obj to file object p.

int PyFile_WriteString (char *s, PyFileObject *p, int flags)
Writes string s to file object p.


Send comments on this document to python-docs@python.org.