Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68417
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: Correct idiom for determining path when frozen in 3.4 |
| Date | 2014-03-17 20:23 +1100 |
| References | <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> <85ha6xp59k.fsf@benfinney.id.au> <CABicbJK9tyNoiPMKZdLqYoebrsWXPet7YxWPUo4s7_j9P7NBkg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8182.1395048251.18130.python-list@python.org> (permalink) |
Devin Jeanpierre <jeanpierreda@gmail.com> writes: > 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. > […] > Sure, but sys.executable always exists. My apologies for posting untested code without making that clear. Thanks to Devin for picking up my mistakes. > > 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) > sys.frozen doesn't [necessarily exist], and the existence or > nonexistence is apparently meaningful; so your code does something > different than the original problem statement. Right. I didn't understand why ‘__file__’ is a suitable substitute for ‘sys.executable’; they're always (?) different values. So that probably is what led to the confusion in the code behaviour. I hope the Pythonic idioms are helpful to the original poster nevertheless. -- \ “Anyone who believes exponential growth can go on forever in a | `\ finite world is either a madman or an economist.” —Kenneth | _o__) Boulding | Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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