[Tutor] Need help printing a pickled data

Matt D md123 at nycap.rr.com
Wed Jun 26 02:35:03 CEST 2013


On 06/25/2013 02:02 PM, Prasad, Ramit wrote:
> Again, please leave in attributions.
> 
> Matt D wrote:
>> [Ramit Prasad wrote]
>>>
>>> Well I think self.data is some kind of container with a pickled string,
>>> given the code to unpickle it is:
>>>
>> Exactly!  This is what the C++ file 'pickle.h' creates to send to the
>> Python GUI:
> 
> Not really.
> 
>>
>>
>> /**
>>  * A pickled Python dictionary. Used to pass stuff to the UI.
>>  */
>> class pickle
>> {
>>
> [snip C++ code]
>>
>> };
> 
> You can call it a pickle, but it is not actually a pickle. It is
> a wrapper around pickled data. That is *not* the same thing. 
> 
confusing
so that code above is the wrapper of what the code below makes, which is
pickled data?:


pickle::pickle()
{
}

pickle::~pickle()
{
}

void
pickle::add(string key, string value)
{
   map_[key] = value;
}

string
pickle::to_string() const
{
   size_t n = 1;
   ostringstream os;
   os << "(dp" << n++ << endl;
   for(stringmap::const_iterator i(map_.begin()); i != map_.end(); ++i) {
      os << "S'" << i->first << "'" << endl;
      os << "p" << n++ << endl;
      os << "S'" << i->second << "'" << endl;
      os << "p" << n++ << endl << "s";
   }
   os << "." << endl;
   return os.str();
}




More information about the Tutor mailing list