Rationale for read-only property of co_code
Scott David Daniels
Scott.Daniels at Acm.Org
Wed Apr 2 23:43:08 EDT 2008
João Neves wrote:
> On 2 Abr, 21:38, "Chris Mellon" <arka... at gmail.com> wrote:
>> On Wed, Apr 2, 2008 at 2:33 PM, João Neves <seve... at gmail.com> wrote:
>>> On Apr 2, 5:41 pm, "Dan Upton" <up... at virginia.edu> wrote:
>>> > > The thing I've been wondering is why _is_ it read-only? In what
>>> > > circumstances having write access to co_code would break the language
>>> > > or do some other nasty stuff?....
>> There is no need to overwrite co_code. Create a new code object with
>> your desired bytecode and use that instead.
>
> Yes, it may work (haven't tested - isn't there any problem with stuff
> like co_name, for instance?), but for simplicity's sake, wouldn't it
> be far more convenient if you could just write over co_code? :)
> In the end, it's all a matter of convenience, I guess.
Nope: If you change the code in-place, the whole stack's references
to where they were running would need to get updated to corresponding
locations in the new code. _That_ is a lot of work.
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list