6.5 Constructors

PyObject* PyFile_FromString(char *file_name, char *mode)
On success, returns a new file object that is opened on the file given by file_name, with a file mode given by mode, where mode has the same semantics as the standard C routine fopen(). On failure, return -1.

PyObject* PyFile_FromFile(FILE *fp, char *file_name, char *mode, int close_on_del)
Return a new file object for an already opened standard C file pointer, fp. A file name, file_name, and open mode, mode, must be provided as well as a flag, close_on_del, that indicates whether the file is to be closed when the file object is destroyed. On failure, return -1.

PyObject* PyFloat_FromDouble(double v)
Returns a new float object with the value v on success, and NULL on failure.

PyObject* PyInt_FromLong(long v)
Returns a new int object with the value v on success, and NULL on failure.

PyObject* PyList_New(int len)
Returns a new list of length len on success, and NULL on failure.

PyObject* PyLong_FromLong(long v)
Returns a new long object with the value v on success, and NULL on failure.

PyObject* PyLong_FromDouble(double v)
Returns a new long object with the value v on success, and NULL on failure.

PyObject* PyDict_New()
Returns a new empty dictionary on success, and NULL on failure.

PyObject* PyString_FromString(char *v)
Returns a new string object with the value v on success, and NULL on failure.

PyObject* PyString_FromStringAndSize(char *v, int len)
Returns a new string object with the value v and length len on success, and NULL on failure. If v is NULL, the contents of the string are uninitialized.

PyObject* PyTuple_New(int len)
Returns a new tuple of length len on success, and NULL on failure.

guido@python.org