How to save mesh data to text

Sometimes it is necessary to save data for creating a mesh (its vertices and polygon indices arrays) to text, for example, for further use in a script or addon.

We can export the mesh to one of the open formats, for example, to *.obj, but if we need only its vertexes and polygons data, we can use the following simple script:

Here we set the file name for saving data, make two arrays with vertexes and polygons data and save them to the specified file.

For example, for the default cube we get the following result:

We can now use this saved data, for example, copying them to a script.

The following script after executing will create a new default cube in the scene: