Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'exists.': 0.07; 'executable': 0.09; 'sure,': 0.09; 'try:': 0.09; 'cc:addr:python- list': 0.11; '__file__)': 0.16; 'finney': 0.16; 'getattr(sys,': 0.16; 'pythonic': 0.16; 'statement.': 0.16; 'subject:when': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'cc:addr:python.org': 0.22; 'replace': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'raise': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'apparently': 0.31; 'existence': 0.31; 'writes:': 0.31; "i'd": 0.34; 'problem': 0.35; 'except': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'skip:o 20': 0.38; 'ben': 0.38; 'does': 0.39; 'skip:u 10': 0.60; 'more': 0.64; 'different': 0.65; 'skip:\xe2 10': 0.65; 'mar': 0.68; 'default': 0.69; '8bit%:46': 0.78; '2:02': 0.84; 'lastly,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=DS6TwVQn0q8L2+24aKTn36XYgv9ZQYKEgnzxHNZLuJs=; b=m9oUnbsqczrxxQiggMxZq5U9UQq6+FFQMGwuGzajt8F0Hgjdtb+/402ewCvqMQonhM m782GkELOOdVMOkgA81ckv0V7vLt0CcU9Ai/UmCIh1NqP45sF66OWo6pGFuuy1Kw4mbi AhBtA5whgo+0HlqnACyyPyxGMd5DcJ70bWphHpqXawRaPhf0ijn2EJN2ZCp4gBUU+T3L 8oxlBnV0iCbRdJ5UZLBknhAGVntToOMr1n4hh3OM5yZCp5HMC7RepzYuRDDCgFG0anoi Xdud37Saf08jgI5wOT3M/kveiLkRDydrydZBhP3YlCt+pdWIw9smGNFo3swTveuYLjE6 Jz0A== X-Received: by 10.140.91.105 with SMTP id y96mr25957368qgd.3.1395047847685; Mon, 17 Mar 2014 02:17:27 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <85ha6xp59k.fsf@benfinney.id.au> References: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> <85ha6xp59k.fsf@benfinney.id.au> From: Devin Jeanpierre Date: Mon, 17 Mar 2014 02:16:47 -0700 Subject: Re: Correct idiom for determining path when frozen in 3.4 To: Ben Finney Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "comp.lang.python" 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395047855 news.xs4all.nl 2839 [2001:888:2000:d::a6]:55850 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68416 On Mon, Mar 17, 2014 at 2:02 AM, Ben Finney wr= ote: > Mark Summerfield writes: > if getattr(sys, "frozen"): # =E2=80=98getattr=E2=80=99 will return= None by default No it won't. > Lastly, it's slightly more Pythonic to execute the normal path > unconditionally, and let it raise an exception if there's a problem:: > > try: > executable =3D sys.executable > except AttributeError: > executable =3D __file__ > path =3D os.path.dirname(executable) Sure, but sys.executable always exists. sys.frozen doesn't, and the existence or nonexistence is apparently meaningful; so your code does something different than the original problem statement. Also, if that weren't the case, I'd really replace that try-except with getattr(sys, 'executable', __file__) -- Devin