Environment vars

Chris Angelico rosuav at gmail.com
Wed Nov 25 12:59:46 EST 2020


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. :)

ChrisA


More information about the Python-list mailing list