How do I modify my callers local variables?

Terry Reedy tjreedy at
Tue Feb 13 03:57:50 CET 2001

> def parse_keywords(defaults,kw):
>     import sys
>     try:
>         raise None
>     except:
>         frame = sys.exc_info()[2].tb_frame.f_back
>         locals_dict=frame.f_locals

This only gives you a PyDict copy of the function locals, which happen to
be internally implemented as an indexed C array.

>     for i in defaults.keys():
>         try:
>             locals_dict[i]=kw[i]
>         except KeyError:
>             try:
>                 locals_dict[i]=defaults[i]

Modifying your PyDict copy has no effect on the internal C array that the
function actually uses.  Thus this assignment in useless in terms of what
you hope to accomplish.

> ...
> I'd really appreciate any insights into this matter.

I hope this helps.

Terry J. Reedy

More information about the Python-list mailing list