On Wed, Jun 20, 2012 at 10:28 AM, Gavin Panella
<email address hidden> wrote:
> On 19 June 2012 21:46, Robert Collins <email address hidden> wrote:
> ...
>> (assuming msg is a unicode object, not a bytestring). If msg is a
>> bytestring, then:
>> if msg:
>> details['STDOUT:'] = content.Content(content_type.UTF8_TEXT, lambda:[msg])
>
> This will keep a reference to msg in the enclosing scope. A quick look
> at the code shows that msg is changed later in the function, so this
> will break, hence the need for the partial() I think.
Oh! So, I'd wrap the two lines in a helper, that will break the
scoping problem and be shorter overall:
On Wed, Jun 20, 2012 at 10:28 AM, Gavin Panella Content( content_ type.UTF8_ TEXT, lambda:[msg])
<email address hidden> wrote:
> On 19 June 2012 21:46, Robert Collins <email address hidden> wrote:
> ...
>> (assuming msg is a unicode object, not a bytestring). If msg is a
>> bytestring, then:
>> if msg:
>> details['STDOUT:'] = content.
>
> This will keep a reference to msg in the enclosing scope. A quick look
> at the code shows that msg is changed later in the function, so this
> will break, hence the need for the partial() I think.
Oh! So, I'd wrap the two lines in a helper, that will break the
scoping problem and be shorter overall:
def attach(label, msg):
details[ label] = content. Content( content_ type.UTF8_ TEXT, lambda:[msg]) stream_ output( sys.stdout) ) stream_ output( sys.stderr) )
if msg:
attach('STDOUT:, _get_new_
attach('STDERR:, _get_new_
5 lines vs 6, and less partial gymnastics ;)
-Rob