Re: marshal.loads ValueError



Hello,

abcd wrote:

I have the following code which is sent over the wire as a string...

from time import time
class Foo:
def go(self):
print "Time:", time()


I get this code and store it as, "data"

data = receivePythonSource()

Then I try...

exec marshal.loads(data) in my_module.__dict__

However I get an error saying:
ValueError: invalid literal for __float__: om time import time
class Foo:
def go(self):

....almost like when I try to marshal and exec it misses the first two
characters, "fr" ...any ideas?

marshal is used to (de)serialize python objects from/to strings.
marshal.loads() tries to deserialize an encoded string back into a python
object - which does not make sense here.
What you probably want is:

exec data in my_module.__dict__


HTH

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
.



Relevant Pages

  • Re: Ruby vs Perl performance
    ... It is fun, though. ... def initialize some, random, args ...
    (comp.lang.ruby)
  • Re: Meta-Meta-Programming
    ... def just_wrap ... *args, not &block. ... but it does sound good: monitor-functions. ...
    (comp.lang.ruby)
  • Re: Meta-Meta-Programming
    ... def just_wrap ... *args, not &block. ... but it does sound good: monitor-functions. ...
    (comp.lang.ruby)
  • Meta-Meta-Programming
    ... def just_wrap ... *args, not &block. ... but it does sound good: monitor-functions. ...
    (comp.lang.ruby)
  • Re: When are attr_reader type methods called?
    ... > def call_this ... This will work as the method bar exists and belongs to the class Foo, ... hoo # this will raise a NoMethodError, ... call them inside your class definitions -- they are methods available ...
    (comp.lang.ruby)