Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; 'integers': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"=="': 0.16; '"is"': 0.16; "'is',": 0.16; 'compares': 0.16; 'defined.': 0.16; 'docs.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'peek': 0.16; 'set:': 0.16; 'subject:variable': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'later': 0.20; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'choices': 0.24; 'test.': 0.24; 'cc:2**0': 0.24; 'compare': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'flags': 0.31; 'supposed': 0.32; 'another': 0.32; 'comment': 0.34; 'could': 0.34; 'advice': 0.35; 'equal': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'set.': 0.36; 'subject:?': 0.36; 'should': 0.36; 'application': 0.37; 'skip:o 20': 0.38; 'problems': 0.38; 'pm,': 0.38; 'expect': 0.39; 'changed': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'subject:Can': 0.60; 'most': 0.60; 'new': 0.61; 'more': 0.64; 'mar': 0.68; 'end.': 0.84; 'enumeration,': 0.84; 'grave': 0.84; 'order:': 0.84; 'mistake': 0.91; '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=MygsVXzDJmWCF5bv/ytiJc/THkqhn4dE8t3taMJLVVI=; b=LlZPTg02tTCH4qqI9lBkLZ2EwVXqgR2spRl/ESz2FGmWx1SPhgG9VmYKwgiDnuaVG/ 5HMoSPwyOEO9fgQdqFUqTGewNPkeTqjtfpnKyIrpBDTLmIzHM+XZtrKF7ds1WT4vJPRN 1MmTP7VEiH043yLLWU9y0whSoFTm5ty/F7ubJJ8rSwJ/FNLwhkAUlVMMK8+ceL4dtoEw Brjw8RwVqu9gkEjOOgeNrA2OG6Kg0BbUlz0dLChmGS7r1Bk4Q3QmsySVHffVuRgp8L/a wF+FY7t46yFYVU0CmulcFa9n2z5cwXoKtUZ0GDm34Dhj0b6m8nRaHk3AUV1hG0e87hMw ue0A== MIME-Version: 1.0 X-Received: by 10.68.112.164 with SMTP id ir4mr8238pbb.153.1393754859883; Sun, 02 Mar 2014 02:07:39 -0800 (PST) In-Reply-To: <87ha7h9c40.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.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> Date: Sun, 2 Mar 2014 21:07:39 +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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393754868 news.xs4all.nl 2871 [2001:888:2000:d::a6]:58058 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67422 On Sun, Mar 2, 2014 at 8:35 PM, Marko Rauhamaa wrote: > However, on the same reference page, os.posix_fadvise() is defined. We > read: > > advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, > POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or > POSIX_FADV_DONTNEED > > Now, what kinds of object are those constants? We are not supposed to > know or care. We could peek into the implementation, but it would be a > grave mistake to trust the implementation choices in the application. > > So in my application code I might set: > > favd_flag = os.POSIX_FADV_RANDOM > > in some other part of my code I might want to see how "flag" was set. > Should I use "==" or "is" to test it? In the absence of any advice to the contrary, I would use == to test. The flags are most likely to be, in order: * An enumeration, in a sufficiently new Python * Integers * Strings * Arbitrary object()s All of the above will compare correctly with ==, and if someone stuffs in an object that compares equal to more than one of them, they're likely to have problems at the far end. If identity is really crucial, I would expect there to be a comment in the docs. And there's another thing you can do to test. >>> import os >>> type(os.POSIX_FADV_RANDOM) So use ==. If it's later changed and you have to instead use 'is', you can change your code. ChrisA