[Tutor] What is the easiest way to ensure the current working directory is the same as the directory where the main program is saved?
boB Stepp
robertvstepp at gmail.com
Thu Jul 1 20:02:14 EDT 2021
OK, I have just re-read everyone's posts to this thread. Thank you
very much for the detailed replies!
I'm still mulling over all of this and probably will for some time. I
don't think I yet understand all of the nuances of the information
presented. Probably won't truly settle in until I struggle with
enough code in enough varied circumstances..
One thing I realized during the re-read is that my relatively naive
use of the word "data" needs to be more precise. I gather that "data"
might have the following meanings, depending on context:
1) User-generated data external to my program. This assumes that my
program is designed to enable the user to process his data. So she
needs to give my program the path to this data, either through command
line arguments when invoking my program or via a mechanism provided by
my program, probably some sort of file selector widget.
2) My program generates data from the user's use of it. This means
that either the data will be stored in one of the OS-provided standard
locations (such as in Windows %appdata%) or allow the user a choice as
to where to store it, in which case my program must allow the user a
way of providing that path, which then gets stored in my program's
preferences or configuration file in one of the OS-standard locations.
3) Information my program needs to be properly configured is normally
stored in an OS-provided location.
4) User preferences and other user-initiated customization of my
program. Again stored in an appropriate configuration file in an
OS-approved location.
I think that covers most of what was discussed in this thread, though
dn provided some more complex scenarios to contemplate in his usual
inimitable way! In each of these instances my program should have no
need (normally) of using __file__ - based tricks.
One thing that is mildly troubling is that if I wish to write
cross-platform applications then I must go to the bother of detecting
the user's OS and stashing "data" appropriately for that OS. But that
should not normally be too troublesome.
Cameron brought up virtual environments for segregating one's programs
and their dependencies during development. Another topic I have been
putting off. I guess I will have to investigate that soon for some of
the programs I am currently imaging doing. It is hard enough keeping
up with the pace of Python updates and having to reinstall the
packages I use for my personal use!
Question: I am about to embark on writing a relatively small program
that I will use to further explore the use of SQLite for storing data,
something I keep dabbling with off and on. As you know SQLite stores
each database as a single file. In this thread's data location
discussion, where should this database file be stored? And for more
substantial database programs than SQLite, how would that normally be
handled if this database program is integrated into the overall
application structure?
I guess that is all for now. Again, thanks for the very good, detailed help!
boB Stepp
More information about the Tutor
mailing list