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


Groups > comp.lang.python > #57707

Re: Function for the path of the script?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gary.herron@islandtraining.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'skip:o 50': 0.09; 'subject:Function': 0.09; 'subject:script': 0.09; 'python': 0.11; 'def': 0.12; 'finds': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'script.': 0.24; 'fairly': 0.24; "i've": 0.25; 'received:(smtp server)': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'code': 0.31; 'gary': 0.31; 'file': 0.32; 'running': 0.33; 'subject:the': 0.34; 'but': 0.35; 'subject:?': 0.36; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'around.': 0.60; 'reaching': 0.61; 'kind': 0.63; 'myself': 0.63; 'does?': 0.84; 'huh?': 0.84
X-Virus-Scanned OK
Date Sat, 26 Oct 2013 19:52:31 -0700
From Gary Herron <gary.herron@islandtraining.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Function for the path of the script?
References <00704f33-7e7f-4ccf-b28b-69776d2e237d@googlegroups.com>
In-Reply-To <00704f33-7e7f-4ccf-b28b-69776d2e237d@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
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.1634.1382842801.18130.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1382842801 news.xs4all.nl 15985 [2001:888:2000:d::a6]:38208
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:57707

Show key headers only | View raw


On 10/26/2013 07:23 PM, Peter Cacioppi wrote:
> Am I the only one who finds this function super useful?
>
> def _code_file() :
>      return os.path.abspath(inspect.getsourcefile(_code_file))
>
>
> I've got one in every script. It's the only one I have to copy around. For my workflow ... so handy.
>
> I've got os.path.dirname aliased to dn, so its dn(_code_file()) that I find myself reaching for fairly often...

Huh?  In what kind of a workflow are you running a python file without 
knowing *what* file you are runnung?

Or am I just misinterpreting what this code does?

Confused but curious,
Gary Herron

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


Thread

Function for the path of the script? Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-26 19:23 -0700
  Re: Function for the path of the script? Skip Montanaro <skip.montanaro@gmail.com> - 2013-10-26 21:42 -0500
  Re: Function for the path of the script? Gary Herron <gary.herron@islandtraining.com> - 2013-10-26 19:52 -0700
  Re: Function for the path of the script? Chris Angelico <rosuav@gmail.com> - 2013-10-27 14:01 +1100
    Re: Function for the path of the script? Grant Edwards <invalid@invalid.invalid> - 2013-10-28 14:49 +0000
      Re: Function for the path of the script? Chris Angelico <rosuav@gmail.com> - 2013-10-29 01:59 +1100
      Re: Function for the path of the script? rurpy@yahoo.com - 2013-10-28 21:00 -0700
        Re: Function for the path of the script? Steven D'Aprano <steve@pearwood.info> - 2013-10-29 05:27 +0000
          Re: Function for the path of the script? Grant Edwards <invalid@invalid.invalid> - 2013-10-29 14:31 +0000
  Re: Function for the path of the script? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-27 03:42 +0000
  Re: Function for the path of the script? Ben Finney <ben+python@benfinney.id.au> - 2013-10-27 15:10 +1100
    Re: Function for the path of the script? Roy Smith <roy@panix.com> - 2013-10-27 09:38 -0400
    Re: Function for the path of the script? Grant Edwards <invalid@invalid.invalid> - 2013-10-28 14:58 +0000
      Re: Function for the path of the script? Ben Finney <ben+python@benfinney.id.au> - 2013-10-29 09:50 +1100
        Re: Function for the path of the script? Grant Edwards <invalid@invalid.invalid> - 2013-10-29 14:26 +0000
  How to find where data files are installed for my Python program (was: Function for the path of the script?) Ben Finney <ben+python@benfinney.id.au> - 2013-10-27 15:28 +1100
    Re: How to find where data files are installed for my Python program (was: Function for the path of the script?) rurpy@yahoo.com - 2013-10-26 22:18 -0700
    Re: How to find where data files are installed for my Python program Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-10-27 20:58 +1300
      Re: How to find where data files are installed for my Python program Ian Kelly <ian.g.kelly@gmail.com> - 2013-10-27 09:50 -0600
      Re: How to find where data files are installed for my Python program Ben Finney <ben+python@benfinney.id.au> - 2013-10-28 10:13 +1100
      Re: How to find where data files are installed for my Python program Ben Finney <ben+python@benfinney.id.au> - 2013-10-28 10:31 +1100
      Re: How to find where data files are installed for my Python program Chris Angelico <rosuav@gmail.com> - 2013-10-28 10:58 +1100
      Re: How to find where data files are installed for my Python program Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-28 00:34 +0000
      Re: How to find where data files are installed for my Python program Chris Angelico <rosuav@gmail.com> - 2013-10-28 17:51 +1100
        Re: How to find where data files are installed for my Python program Roy Smith <roy@panix.com> - 2013-10-28 08:51 -0400
          Re: How to find where data files are installed for my Python program Chris Angelico <rosuav@gmail.com> - 2013-10-29 00:06 +1100
  Re: How to find where data files are installed for my Python program (was: Function for the path of the script?) Chris Angelico <rosuav@gmail.com> - 2013-10-27 16:49 +1100
  Re: Function for the path of the script? Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-28 15:57 -0700
  Re: Function for the path of the script? Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-28 22:56 -0700

csiph-web