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: 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: References: <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> From: Zachary Ware 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 Content-Type: text/plain; charset=UTF-8 Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Mon, Mar 17, 2014 at 10:31 AM, Mark Summerfield 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 >>> _fi.__spec__ ModuleSpec(name='_frozen_importlib', loader=, origin='') >>> _fi.__spec__.origin '' 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