Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68416

Re: Correct idiom for determining path when frozen in 3.4

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 <jeanpierreda@gmail.com>
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 <jeanpierreda@gmail.com>
Date Mon, 17 Mar 2014 02:16:47 -0700
Subject Re: Correct idiom for determining path when frozen in 3.4
To Ben Finney <ben+python@benfinney.id.au>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc "comp.lang.python" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8181.1395047854.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Mon, Mar 17, 2014 at 2:02 AM, Ben Finney <ben+python@benfinney.id.au> wrote:
> Mark Summerfield <list@qtrac.plus.com> writes:
>     if getattr(sys, "frozen"):    # ‘getattr’ 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 = sys.executable
>     except AttributeError:
>         executable = __file__
>     path = 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Correct idiom for determining path when frozen in 3.4 Mark Summerfield <list@qtrac.plus.com> - 2014-03-17 01:44 -0700
  Re: Correct idiom for determining path when frozen in 3.4 Ben Finney <ben+python@benfinney.id.au> - 2014-03-17 20:02 +1100
  Re: Correct idiom for determining path when frozen in 3.4 Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-03-17 02:16 -0700
  Re: Correct idiom for determining path when frozen in 3.4 Ben Finney <ben+python@benfinney.id.au> - 2014-03-17 20:23 +1100
  Re: Correct idiom for determining path when frozen in 3.4 Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-03-17 09:52 +0000
  Re: Correct idiom for determining path when frozen in 3.4 Mark Summerfield <list@qtrac.plus.com> - 2014-03-17 08:31 -0700
    Re: Correct idiom for determining path when frozen in 3.4 Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-03-17 11:03 -0500

csiph-web