class ExampleObject(object): """ Class to contain all the input related logic so it's all in one place """ def __init__(self, start_month, end_month, foo): self.start_month = start_month self.end_month = end_month self.foo = foo def __str__(self): return "ExampleObject(%s,%s,%s)"%(self.start_month, self.end_month, self.foo)class ExampleObjectParameter(luigi.Parameter): def parse(self, x): # Make sure the incoming string matches str(ExampleObject())'s output assert x.find("ExampleObject")==0, "Parse failed: \"ExampleObject\" not found in string." # Ignore the module name and the parens, but split the rest into arguments arguments = x[14:-1].split(',') # Make sure there's exactly 3 args assert len(arguments)==3, "Parse failed: Expected 3 arguments, but got %s"%(len(arguments)) # Return the ExampleObject instance return ExampleObject(arguments[0], arguments[1], arguments[2])--
You received this message because you are subscribed to the Google Groups "Luigi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to luigi-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class ExampleObject(object):
def __init__(self, start_month, end_month, foo):
self.start_month = start_month
self.end_month = end_month
self.foo = foo
def __str__(self):
return json.dumps({'start_month': self.start_month, 'end_month': self.end_month, 'foo': self.foo})
class ExampleObjectParameter(luigi.Parameter):
def parse(self, x):
return ExampleObject(**json.loads(x))
If you want to keep the object name (ExampleObject) in the __str__ of the object you might use a little more complex JSON serialization.
BTW, good solution and thanks to share that problem.
Cheers,