[Tutor] Running python files - solved

Phil phillor9 at gmail.com
Fri Oct 16 19:41:23 EDT 2020


On 14/10/20 10:16 am, Alan Gauld via Tutor wrote:
> On 14/10/2020 00:28, Phil wrote:
>> This seemingly simple problem has me scratching my head. How do I run a
>> python file from a directory other than the directory that the python
>> file is in?
> There are several ways to do this.
> 1) Use a hard coded full path.
> 2) Put the full path in a config variable in a config file
> 3) Get the path from an environment variable (and have a default if not set)
> 4) change the current working directory to the folder your file is in
> (using the os.chdir() function)

Thank you everyone for your replies. However, I think my question was 
not fully understood, no doubt to my clumsiness. Anyway I have a 
solution, although I did take me some time to realise how simple the 
solution is.

What I did was to create a launcher bash script that I have stored in my 
home directory. The launcher script changes to the directory where the 
python script is stored and then runs the python script. The system menu 
calls the launcher script.

-- 

Regards,
Phil



More information about the Tutor mailing list