Environment vars

Bob van der Poel bob at mellowood.ca
Wed Nov 25 13:26:17 EST 2020


On Wed, Nov 25, 2020 at 10:59 AM Chris Angelico <rosuav at gmail.com> wrote:

> On Thu, Nov 26, 2020 at 4:36 AM Bob van der Poel <bob at mellowood.ca> wrote:
> >
> > I've got a program which accepts an optional env variable listing a
> single
> > or multiple directory for the app to use. I've done a bit of a search and
> > see both a comma and semicolon being used/suggested as a path separator.
> > Any consensus on which is better?
> >
> >    MYPATHS=foo,bar,woof
> > or
> >     MYPATHS=foo;bar;woof
> > And, certainly not
> >     MYPATHS=foo,bar;woof
> >
> > I did think I could be clever and check to see if the string contained a
> ,
> > or ; and spit it accordingly, but then what if the reason (hopefully,
> > pretty damned unlikely!) that a , or ; is being used as part of a path
> name?
> >
>
> Both are very much possible. I would recommend following a well-known
> standard; fortunately, there are plenty to choose from.
>
> 1) Separate them with spaces, because words.
> 2) Separate them with commas, because lists in English.
> 3) Separate with colons the way $PATH is.
>
> Whichever way you do it, you'll have to cope with the possibility that
> the character exists in a path name. That means you'll either need an
> escaping system (eg "\ " meaning a space, or ",," meaning a comma) or
> a quoting system (so "foo,bar",woof would mean two entries, the first
> of which contains a comma). Or you just acknowledge that MYPATHS is
> unable to represent something with the delimiter - which is how $PATH
> works - and then you'll probably need some workaround for that, like
> maybe a command line argument.
>
> The one thing I really would *not* recommend is a DWIM arrangement of
> having it guess at which delimiter to use. :)
>

Thanks Chris.

What does DWIN mean?

Hmmm, using colons? Yet another option :)

Spaces ... nope. That means the entire option will need to be quoted to
escape the shell's work.

So, back to commas or semicolons. I think I'll just stick with the commas
'cause I already wrote it that way :)


-- 

**** Listen to my FREE CD at http://www.mellowood.ca/music/cedars ****
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bob at mellowood.ca
WWW:   http://www.mellowood.ca


More information about the Python-list mailing list