[Tutor] What is the easiest way to ensure the current working directory is the same as the directory where the main program is saved?
dn
PyTutor at DancesWithMice.info
Sat Jul 3 23:24:40 EDT 2021
On 04/07/2021 05.40, boB Stepp wrote:
> On Sat, Jul 3, 2021 at 3:32 AM Alan Gauld via Tutor <tutor at python.org> wrote:
>>
>> On 02/07/2021 01:02, boB Stepp wrote:
>>
>>> 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.
>
> [...]
>
>> When you add the possibility of the user having a config that
>> over-rides the OS default too, it gets even more messy.
>> It is a non-trivial exercise.
>
> I said, "...But that should not normally be too troublesome." I am
> now a troubled man with a worried mind! ~(:>))
Well, we can't have that!
Let's see if I can trivialise your thoughts by complicating matters...
Sound-track (https://www.youtube.com/watch?v=fX5USg8_1gA) to ease your
troubled mind, is "Layla" by Eric Clapton! Follow that up with a little
Myles Kennedy
(https://www.tekstowo.pl/piosenka,myles_kennedy,worried_mind.html)
Some people, when confronted with a problem, think
“I know, I'll use regular expressions.”
Now they have two problems.
- (attributed to) Jamie Zawinski
Consider (as one of our colleagues is wont to ask):
"The real problem is that programmers have spent far too much time
worrying about efficiency in the wrong places and at the wrong times;
premature optimization is the root of all evil (or at least most of it)
in programming."
Donald Knuth, Computer Programming as an Art (1974)
- in this case might "efficiency" be represented as trying to make
something work under all OpSys - other than the one you happen to be
using, today.
Might it be better (use of your (learning-) time) to simplify this
consideration, and move-on?
aka
Is it part of the MVP of your project?
(in this case, perhaps the "learning" value takes place inside your own
head, cf amongst potential clients)
Thus, how about building a function which sets the applicable/default
directory? Today it can return a constant. Tomorrow you can make the
working application more flexible/powerful...
When you feel like you're walking a tight-rope, see also "Technical Debt"...
There now, don't you feel so much better!
(?)
Musical accompaniment to your whirring thoughts:
https://www.youtube.com/watch?v=FgcGOWaTPdU
[not to be used by folk affected by a suicide, and more applicable to
those of us old-enough to remember the TV show it introduced]
Web.Refs:
https://www.explainxkcd.com/wiki/index.php/208:_Regular_Expressions
https://en.wikiquote.org/wiki/Donald_Knuth
debated at https://news.ycombinator.com/item?id=1671458
https://stackify.com/premature-optimization-evil/
http://passionateaboutoss.com/premature-optimisation/
https://www.agilealliance.org/glossary/mvp/
https://en.wikipedia.org/wiki/Technical_debt
https://www.agilealliance.org/introduction-to-the-technical-debt-concept
https://www.projectpractical.com/technical-debt/
--
Regards,
=dn
More information about the Tutor
mailing list