file location/directory

dn PythonList at DancesWithMice.info
Sun Mar 14 17:45:04 EDT 2021


On 15/03/2021 07.44, 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?


Perhaps I'm confused:
a) are we talking about multiple Python program[me]s, or
b) multiple data-files which will be accessed by the same code?

a) Python will set the current directory according to where/how it is
started from the command-line.

b) consider that a file is addressed by more than just its name. Let's
over-simplify and talk about it having a "file-name", and having a
location which is described by a "path". Python will happily choose a
file based upon its "file-name" only - which implies that it is located
in the "current working directory"; or you can use both components, eg

open( os.path.join( path, file_name )...

So, now by setting the "path" according to "that folder", and adding the
requisite file-name(s), will that answer the need?

Remember that a path may be "absolute" or "relative", according to need.
-- 
Regards,
=dn


More information about the Python-list mailing list