Getting the current directory path and the path where python script is saved
Neil Cerutti
neilc at norwich.edu
Tue Dec 13 11:29:08 EST 2011
On 2011-12-13, gialloporpora <gialloporpora at 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
More information about the Python-list
mailing list