pack an integer into a string

superpollo user at example.net
Fri Jul 24 18:58:07 EDT 2009


Sebastian Bassi wrote:
> On Fri, Jul 24, 2009 at 7:28 PM, superpollo<user at example.net> wrote:
> 
>>is there a pythonic and synthetic way (maybe some standard module) to "pack"
>>an integer (maybe a *VERY* big one) into a string? like this:
> 
> 
> What do you mean to pack? Maybe Pickle is what you want.
> 
> import cPickle
> variable = 124348654333577698
> cPickle.dump(variable,open('filename', 'w'))
> 
> To load it:
> 
> import cPickle
> vaariable = cPickle.load(open('filename'))
> 
> It is not "into a string", but instead of a filename, use a string with stringio


  >>> number
  252509952
  >>> f = cStringIO.StringIO()
  >>> cPickle.dump(number , f)
  >>> f.getvalue()
  'I252509952\n.'
  >>>

as you can see, the pickled representation is not what i wanted...

thanks anyway

bye



More information about the Python-list mailing list