MCPcopy Create free account
hub / github.com/numpy/numpy / array_tofile

Function array_tofile

numpy/core/src/multiarray/methods.c:653–700  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

651 */
652
653static PyObject *
654array_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)
655{
656 int own;
657 PyObject *file;
658 char *sep = "";
659 char *format = "";
660 static char *kwlist[] = {"file", "sep", "format", NULL};
661
662 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss:tofile", kwlist,
663 &file,
664 &sep,
665 &format)) {
666 return NULL;
667 }
668
669 file = NpyPath_PathlikeToFspath(file);
670 if (file == NULL) {
671 return NULL;
672 }
673 if (PyBytes_Check(file) || PyUnicode_Check(file)) {
674 Py_SETREF(file, npy_PyFile_OpenFile(file, "wb"));
675 if (file == NULL) {
676 return NULL;
677 }
678 own = 1;
679 }
680 else {
681 own = 0;
682 }
683
684 int file_ret = PyArray_ToFileObject(self, file, sep, format);
685 int close_ret = 0;
686
687 if (own) {
688 PyObject *err_type, *err_value, *err_traceback;
689 PyErr_Fetch(&err_type, &err_value, &err_traceback);
690 close_ret = npy_PyFile_CloseFile(file);
691 npy_PyErr_ChainExceptions(err_type, err_value, err_traceback);
692 }
693
694 Py_DECREF(file);
695
696 if (file_ret || close_ret) {
697 return NULL;
698 }
699 Py_RETURN_NONE;
700}
701
702static PyObject *
703array_toscalar(PyArrayObject *self, PyObject *args)

Callers

nothing calls this directly

Calls 5

NpyPath_PathlikeToFspathFunction · 0.85
npy_PyFile_OpenFileFunction · 0.85
PyArray_ToFileObjectFunction · 0.85
npy_PyFile_CloseFileFunction · 0.85

Tested by

no test coverage detected