title: Read write classes to files in an efficent way
body: <p>I have want to save classes to a file in python.
  I want something like this, I have a similar class in python, like this C++ struct:</p>
  
  <pre><code>   struct WebSites
     {
           char SiteName[100];
           int Rank;
     };
  </code></pre>
  
  <p>and I want to write something like this:</p>
  
  <pre><code> void write_to_binary_file(WebSites p_Data)
   {
        fstream binary_file("c:\\test.dat",ios::out|ios::binary|ios::app); 
        binary_file.write(reinterpret_cast&lt;char *&gt;(&amp;p_Data),sizeof(WebSites));
        binary_file.close();
   }
  </code></pre>
  
  <p>which could be read simply by this:</p>
  
  <pre><code>     void read_from_binary_file()
       {
           WebSites p_Data;
           fstream binary_file("c:\\test.dat",ios::binary|ios::in);
           binary_file.read(reinterpret_cast&lt;char *&gt;(&amp;p_Data),sizeof(WebSites));
           binary_file.close();
  
           cout&lt;&lt;p_Data.SiteName&lt;&lt;endl;
           cout&lt;&lt;"Rank :"&lt;&lt; p_Data.Rank&lt;&lt;endl;
  
       }
  </code></pre>
  
  <p>is there a method in python to do this?</p>