file location/directory

dn PythonList at DancesWithMice.info
Tue Mar 16 17:26:52 EDT 2021


On 17/03/2021 02.02, Gys wrote:
> On 3/14/21 7:44 PM, Quentin Bock wrote:
>> how can I change the path that python takes to run certain files, I'm
>> starting to create game and I want those in separate folders, so how
>> can I
>> change it so that python runs the program with the files from that
>> folder?


> this is a very dense subject. The simplest sulution is to create a

+1


> MainFolder with the main module of your game. Then in that folder,
> create a SubFolder where you can store the modules your game wants to
> import.

+1
- and start the game from "MainFolder", ie make that the "current
working directory".


> The alternative is to use the Environment variable $PYTHONPATH

Why not manipulate os.path directly instead of using $PYTHONPATH?
(this might turn into a philosophical discussion...)


> Setting Your PYTHONPATH environment variable (Linux/Unix/OsX)
> 
> Open your personal .bashrc file at /home/<YourName>/.bashrc

The above assumes a *nux OpSys. That being an aspect of the "dense
subject"! If you (OP) intend to distribute this game to other
users/systems, then it is important to be aware of the myriad
differences and 'gotchas'.

Another such challenge is to ensure that everything-needed will be
included in the s/w-delivery - it is very easy to manually copy-over one
directory, but equally easy to forget some (non-sub-directory) companion
library.

In the case of $PYTHONPATH, you will either have to provide a mechanism
to install such for your users, or ask them to do it manually!

(hint: users want to play the game, so don't expect them to be *nix
command-line experts)
-- 
Regards,
=dn


More information about the Python-list mailing list