Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; '128': 0.09; 'integers': 0.09; 'means,': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'begging': 0.16; 'bitwise': 0.16; 'define:': 0.16; 'flags,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'identities.': 0.16; 'integers,': 0.16; 'subject:variable': 0.16; 'underlying': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'normally': 0.19; 'cc:addr:python.org': 0.22; 'recognize': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'am,': 0.29; 'mode': 0.30; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'equality': 0.31; 'flags': 0.31; 'though.': 0.31; 'class': 0.32; 'style': 0.33; 'except': 0.35; 'beyond': 0.35; 'objects': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'does': 0.39; 'sure': 0.39; 'read': 0.60; 'subject:Can': 0.60; 'lower': 0.61; "you're": 0.61; 'happen': 0.63; 'mar': 0.68; 'special': 0.74; '512': 0.84; 'checks.': 0.84; 'directory:': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=b1VzVkGvv+ZGU8eugE4OblYFg67jVB9F7AFFyzKMi5w=; b=Fz9Epua8tMnJfdDb9kqEq7+LQj4IpkhRgzpOZ32J0WlsKHie40QoV9CDGQ9n292Bvw s2GT4F6EwJ7PObI8yI/55KHzdFLaer2IcGq9UwB3eNEiIq/qF7JLa4Ei+P2/8bd4YNZN b84N5HQL8WZhod1s2liVIrdEZLLs1tAD60dPo3Zg+UG0ooNIQHVq7TPz/Twj77dUwDkU LjTw91omT9alKFLSX/FjCUsMRk99g8uFq0Psd42jt+G9uuGCVOfcs1lsegsgWtUTSMim ZwLNrma5NqwdMVwJVphZgeP+2aY12HqbCqQKNnwvBSO934cQ/Q7VBi8E2qLhEboIaZKM I8lA== MIME-Version: 1.0 X-Received: by 10.68.249.100 with SMTP id yt4mr49234pbc.165.1393795697631; Sun, 02 Mar 2014 13:28:17 -0800 (PST) In-Reply-To: <87txbg48kd.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <87k3ceeq0m.fsf@elektro.pacujo.net> <87zjlad8q4.fsf@elektro.pacujo.net> <874n3irz04.fsf@elektro.pacujo.net> <87k3ceqhti.fsf@elektro.pacujo.net> <87mwh9969m.fsf@elektro.pacujo.net> <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> <87ha7h9c40.fsf@elektro.pacujo.net> <87txbg48kd.fsf@elektro.pacujo.net> Date: Mon, 3 Mar 2014 08:28:17 +1100 Subject: Re: Can global variable be passed into Python function? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393795705 news.xs4all.nl 2956 [2001:888:2000:d::a6]:51725 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67469 On Mon, Mar 3, 2014 at 8:03 AM, Marko Rauhamaa wrote: > If one were begging for trouble, one *could* define: > > class ABC: > A = 1 > B = 1.0 > C = 1+0j You're missing the point of flags, though. One does not use floats for flags. Flags are normally going to be integers (passed directly to an underlying C API), strings (self-documenting), or arbitrary objects with no value beyond their identities. In all cases, value equality is the normal way to recognize them, except in the special case of bit-flag integers, where you use bitwise operations (and then equality checks, possibly): DIRECTORY = 512 # Not sure that one's right, tbh OWNER_READ = 256 OWNER_WRITE = 128 OWNER_EXEC = 64 GROUP_READ = 32 ... OTHERS_EXEC = 1 mode = 1005 if mode & DIRECTORY: # It's a directory! if mode & OTHERS_READ: # You're allowed to read (eg 'ls') if mode & GROUP_EXEC: # You get the idea. With multi-bit flags you might have to do a bitwise AND followed by an equality check: NOT_STICKY = 0 STICKY_PARTIAL = 16 STICKY_MOSTLY = 32 STICKY_ENTIRELY = 48 STICKY_BITS = 48 if style & STICKY_BITS == STICKY_MOSTLY: # I've no idea what this means, actually At no time can you do identity checks. It might happen to work with the lower bit values and CPython, but when you check the 2048 bit, you don't get that. Value is all that matters. ChrisA