Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '*args,': 0.07; 'override': 0.07; 'global,': 0.09; 'name):': 0.09; 'naturally': 0.09; 'pgp': 0.09; 'skip:g 60': 0.09; 'specifying': 0.09; 'received:141': 0.13; 'def': 0.14; 'argument': 0.15; 'explicitly': 0.15; 'message-----': 0.15; '-----begin': 0.16; '-----end': 0.16; 'gnupg': 0.16; 'hash:': 0.16; 'received:78.47': 0.16; 'self.kwargs': 0.16; 'skip:6 60': 0.16; 'skip:d 60': 0.16; 'wrote:': 0.16; 'thoughts': 0.18; 'shell': 0.18; 'versions': 0.20; 'settings.': 0.22; 'pass': 0.22; 'module': 0.23; 'header:In-Reply-To:1': 0.24; 'signed': 0.24; 'header:User-Agent:1': 0.26; 'object,': 0.27; '**kwargs):': 0.29; 'idea,': 0.29; 'skip:i 60': 0.29; 'skip:m 60': 0.29; 'function': 0.30; 'allows': 0.30; 'keyword': 0.31; 'skip:_ 10': 0.32; 'class': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'version:': 0.33; 'subject:?': 0.34; 'to:addr:python-list': 0.35; 'false': 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'to:addr:python.org': 0.39; 'subject:the': 0.40; 'default': 0.61; 'different': 0.64; 'charset:windows-1252': 0.65; 'skip:w 60': 0.84; 'subject:Set': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wielicki.name; s=k001.sol; t=1434448845; bh=O68OJlCxZzb+PS/getYqwchUuASYmb9KIB/l8BAoOAM=; h=Date:From:To:Subject:References:In-Reply-To; b=mdebIifl7CUU4rHW3BKpNX1u5Su62dvJ+xKljkX1fkwZEFOBbtrMfl4ZpE4VeYScw gzYwUKSHvk11CjuoffBKfg1qvw8UExVyWl0s2L88GUyhm/gcOiz80IQYjzw9wjYZfL L4spBT+07AaLCMT/j5yTeYlfF/iud4+p+rB+AQVgOApiqTREY/8vgVh04/aPgyYJ3Z qNhtuyYekt1r3sl2WCstnaKFh7kZxqtowmqGuF7NUbeaEzOy1Kd7SduC8e1AEFJSTk vcPKnvYeWuOwon2r5YA2e41fTDXaQ4I3p2WPGhL2jJlVDczMgCWpz1yNQkObyLXKD0 vAfSKSqguRkjg== Date: Tue, 16 Jun 2015 12:00:43 +0200 From: Jonas Wielicki User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Set a flag on the function or a global? References: <557f6676$0$21718$c3e8da3@news.astraweb.com> In-Reply-To: <557f6676$0$21718$c3e8da3@news.astraweb.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 69 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434448862 news.xs4all.nl 2864 [2001:888:2000:d::a6]:57240 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92669 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On 16.06.2015 01:57, Steven D'Aprano wrote: > Alternatively, I can use a flag set on the function object itself: > > edir.dunders = False > > > Naturally you can always override the default by explicitly > specifying a keyword argument edir(obj, dunders=flag). > > Thoughts and feedback? Please vote: a module global, or a flag on > the object? Please give reasons, and remember that the function is > intended for interactive use. I like a flag on the object, and this would be my implementation: ``` def edir_impl(): # implementation of edir pass class Edir(object): def __init__(self): self.kwargs = {} def __getattr__(self, name): return self.kwargs[name] def __setattr__(self, name, value): self.kwargs[name] = value def __delattr__(self, name): del self.kwargs[name] def __call__(self, *args, **kwargs): kwargs_to_use = self.kwargs.copy() kwargs_to_use.update(kwargs) edir_impl(*args, **kwargs_to_use) edir = Edir() ``` (untested, but you get the idea, hopefully) This also allows to have several versions of edir around in a shell with different default settings. regards, jwi -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJVf/PLAAoJEMBiAyWXYliKFM4P/jf/ZDZFacrRuk29tNzNFjA2 6UT4GURF6UX+C129gGgaqxpDY9oD9herfUpqbFxfNWq4Rye9MX+xkv3uQUsP5BXE G7VjrSC0qd1GmdwFxdIQEb1fa6LgMmOnnYe/sIw5XWF2Rtbkqlisw7ZO3YDsWT9d cadoEh0ShFbM6z4MUDEd8tu6RQ/j61v906TwsVgY+4uI8WWOzqHumM7pkWHxP2ns 3b/2ijQJNNLwH3UfbPBo3YhJWt0c+ACzuxr5MamVHUJBZpNatcszti3mkn2CtDCb m5Kc0gO0RxHVaHV4RWrjYlcllhysQ/zeAuOz1PHEqevlitj8z1cBy3p4sfz8GOZe XAKChaZHVAq7eTGzgtLksBQ0dujLxy9zLWiHfeLfMnTyZoYFKVCM2rlSYutnkI0f 7VdaaKStVpqkXeJHX1n1LvHBOroQCFtUFn2F0FylpR/nBA7ar9epZYiCWbrb21xO DYs8T7dC7DI1waLeXJ2JbXiXqh6cQ9Fy86fm+VE1lmkJ6LvboRCN9eWMQ1o1+RtM Dla6CvH2zxgW2u3HZCIoU9TusYaNLR9kSxqCMc2yLuMiUQpj0HfjZCR+ZP2/9phS wx+qZx+5X25ybXlCZRtlvzb409BclOJ7JOynboX4MU4M9sSCPJhb5/ZcM79r7nJa o0y06nE5eReu71TMwmDW =r9uV -----END PGP SIGNATURE-----