Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17143 > unrolled thread
| Started by | gialloporpora <gialloporpora@gmail.com> |
|---|---|
| First post | 2011-12-13 17:04 +0100 |
| Last post | 2011-12-13 17:38 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
Getting the current directory path and the path where python script is saved gialloporpora <gialloporpora@gmail.com> - 2011-12-13 17:04 +0100
Re: Getting the current directory path and the path where python script is saved Neil Cerutti <neilc@norwich.edu> - 2011-12-13 16:29 +0000
Re: Getting the current directory path and the path where python script is saved gialloporpora <gialloporpora@gmail.com> - 2011-12-13 22:39 +0100
Re: Getting the current directory path and the path where python script is saved Thomas Bach <bachth@uni-mainz.de> - 2011-12-13 17:38 +0100
| From | gialloporpora <gialloporpora@gmail.com> |
|---|---|
| Date | 2011-12-13 17:04 +0100 |
| Subject | Getting the current directory path and the path where python script is saved |
| Message-ID | <jc7t7n$u95$1@tdi.cu.mi.it> |
Dear all, I would like to create a little script to rename my files, I think to use argparse module to create it. I would like to know how to obtain the path where script is executed and the path where the file script is stored. For example, if I save my script in c:\python27 and I put the directory in %path% I can execute it from any folder, I would like to get the two directory path. Thanks Sandro -- *gialloporpora: RT @themitcho: telnet miku.acm.uiuc.edu Do it now. You will not regret it. #nyan /via @beaulebens * - http://bit.ly/u2boVC Sto ascoltando: *Pink Floyd – Echoe Part I * - http://bit.ly/vgIGQe
[toc] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2011-12-13 16:29 +0000 |
| Message-ID | <9kpcqkFcoU1@mid.individual.net> |
| In reply to | #17143 |
On 2011-12-13, gialloporpora <gialloporpora@gmail.com> wrote: > Dear all, > I would like to create a little script to rename my files, I think to > use argparse module to create it. > I would like to know how to obtain the path where script is executed and > the path where the file script is stored. > > For example, if I save my script in c:\python27 and I put the > directory in %path% I can execute it from any folder, I would > like to get the two directory path. Current working directory is available with os.getcwd() The location of the script you are running may be available as os.path.basename(sys.argv[0]). -- Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | gialloporpora <gialloporpora@gmail.com> |
|---|---|
| Date | 2011-12-13 22:39 +0100 |
| Message-ID | <jc8gsi$f6t$1@tdi.cu.mi.it> |
| In reply to | #17149 |
Risposta al messaggio di Neil Cerutti : > Current working directory is available with os.getcwd() > > The location of the script you are running may be available as > os.path.basename(sys.argv[0]). Thank you very much, Neil, is exactly what I wanted. Sandro -- *gialloporpora: RT @themitcho: telnet miku.acm.uiuc.edu Do it now. You will not regret it. #nyan /via @beaulebens * - http://bit.ly/u2boVC Sto ascoltando: *Pink Floyd – Echoe Part I * - http://bit.ly/vgIGQe
[toc] | [prev] | [next] | [standalone]
| From | Thomas Bach <bachth@uni-mainz.de> |
|---|---|
| Date | 2011-12-13 17:38 +0100 |
| Message-ID | <87y5ug2zrh.fsf@jubold.box> |
| In reply to | #17143 |
gialloporpora <gialloporpora@gmail.com> writes: > I would like to know how to obtain the path where script is executed > and the path where the file script is stored. Does this help: In [16]: import os In [19]: os.getcwd() Out[19]: '/home/vince' In [21]: os.__file__ Out[21]: '/home/vince/src/pyramid_install/lib/python2.7/os.pyc' regards
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web