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


Groups > comp.lang.python > #68430

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!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <zachary.ware@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.020
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'sys': 0.07; 'cc:addr :python-list': 0.11; 'python': 0.11; 'as-is': 0.16; 'subject:when': 0.16; 'url:faq': 0.16; 'url:whatsnew': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'looked': 0.18; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'this:': 0.26; 'header:In- Reply-To:1': 0.27; 'specifically': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'skip:m 30': 0.32; 'url:python': 0.33; 'skip:_ 10': 0.34; 'skip:s 30': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'should': 0.36; 'url:3': 0.61; 'mar': 0.68; 'url:4': 0.69; 'adapted': 0.84; 'url:latest': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=u5IzQgI1QeD4aWswUVTKk3RVQMGcJ6oFyWkV/qv/Qpw=; b=aBjp8UeAkyuJjk7nwlo6JhYydmEyu8W0lwJWQkaWCThNp+l+YFZ5ta1velISH2uKHQ 8G7uYMpJMs7fdLvLtznHHFWcni3WC2ynzosIDXqIuhwv5Gcf1QrZ1bct9yWau4BWJJmB EGs5Cl2TgN4wkWiyA4HPLF0XnqiuEvx9e82J71bTrOF3DdEdRqoTlu6x1CQfwgEzBwny aVkWytphXOQf7FAnqAjB6IvODnZj2EDICkdF+56cD2c2Mt6vZqZdeoGDUXscAS51MnEk uoF0SIGQSsDzXrvdohMa3zTTP5RtjE7pIS0WeZ/QM25m/nVDNbSuOlH53g6Hi2q3aeAl VVLg==
X-Received by 10.43.156.18 with SMTP id lk18mr1250395icc.77.1395072223327; Mon, 17 Mar 2014 09:03:43 -0700 (PDT)
MIME-Version 1.0
Sender zachary.ware@gmail.com
In-Reply-To <fa3d42dc-fcac-460f-96a7-890513d4e638@googlegroups.com>
References <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> <fa3d42dc-fcac-460f-96a7-890513d4e638@googlegroups.com>
From Zachary Ware <zachary.ware+pylist@gmail.com>
Date Mon, 17 Mar 2014 11:03:10 -0500
X-Google-Sender-Auth RK3Rpx9vKZ5t8N9JJCgSrZyLB0k
Subject Re: Correct idiom for determining path when frozen in 3.4
To Mark Summerfield <list@qtrac.plus.com>
Content-Type text/plain; charset=UTF-8
Cc "python-list@python.org" <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.8199.1395072227.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1395072227 news.xs4all.nl 2890 [2001:888:2000:d::a6]:52491
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:68430

Show key headers only | View raw


On Mon, Mar 17, 2014 at 10:31 AM, Mark Summerfield <list@qtrac.plus.com> wrote:
> My code was adapted from this:
> http://cx-freeze.readthedocs.org/en/latest/faq.html#using-data-files
>
> When you freeze a Python program with cx_Freeze, sys.freeze exists; but otherwise it doesn't.
>
> I develop some programs which I freeze for distribution but during development I test them as-is so I need to be able to distinguish.
>
> Also, from 3.4, __file__ won't exist in frozen modules:
> http://docs.python.org/3.4/whatsnew/3.4.html#changes-in-the-python-api

Have a look at __spec__, specifically __spec__.origin:

>>> import sys
>>> _fi = sys.modules['_frozen_importlib']
>>> _fi
<module '_frozen_importlib' (frozen)>
>>> _fi.__spec__
ModuleSpec(name='_frozen_importlib', loader=<class
'_frozen_importlib.FrozenImporter'>, origin='<frozen>')
>>> _fi.__spec__.origin
'<frozen>'

I've not looked up in the importlib docs to confirm, but that should
mean that frozen modules should have a __spec__.origin that contains
"frozen".

HTH,
-- 
Zach

Back to comp.lang.python | Previous | NextPrevious 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