execute script in certain directory

Alex Popescu the.mindstorm.mailinglist at gmail.com
Mon Jul 9 13:09:40 EDT 2007


On Jul 9, 6:31 pm, brad <byte8b... at gmail.com> wrote:
> When I use idle or a shell to execute a python script, the script
> executes in the directory it is currently in (in this case, my desktop).
> However, when using GNOME and right clicking the py script and selecting
> 'open with python', the execution occurs in my home directory, not my
> desktop.
>
> Is there a way to force py scripts to always run within the directory
> that they reside in?
>
> Thanks
>
> Brad
>
> /home/brad/Desktop/output - python from shell
> /home/brad/Desktop/output - python from idle
> /home/brad/output - python from Gnome 'right click' open with menu

Interesting. I was wondering about the opposit: being in the parent
dir, how can I run a module from a package. (the current behavior when
running python dir_name\module.py is to consider the dir_name the
current dir and this breaks all imports). I am pretty sure this is
answered somewhere, but I must confess that so far I haven't been able
to find it :-(.

TIA,

./alex
--
.w( the_mindstorm )p.





More information about the Python-list mailing list