Access to the caller's globals, not your own

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Nov 16 03:15:17 EST 2016


On Tuesday 15 November 2016 07:04, ojacobson at heroku.com wrote:

> On Monday, November 14, 2016 at 12:21:00 AM UTC-5, Steven D'Aprano wrote:
> 
>> Don't tell me to make SPAMIFY a parameter of the function. I know that.
>> That's what I would normally do, but *occasionally* it is still useful to
>> have a global configuration setting, and those are the cases I'm talking
>> about.
> 
> This is the motivation behind Racket's parameters system
> <http://docs.racket-lang.org/reference/parameters.html>. A _parameter_ has
> the following properties:
[snip]
> Parameterizing a call means that changes to the "global variables"
> implemented as parameters have predictable scope and can be reliably restored
> to their prior values, meaning they're a fairly safe way to implement
> "config" globals.

Sounds more like Python's "with" syntax and context managers, but I'll have a 
read over it the docs and see.


-- 
Steven
299792.458 km/s — not just a good idea, it’s the law!




More information about the Python-list mailing list