Environment vars

Eryk Sun eryksun at gmail.com
Wed Nov 25 17:02:13 EST 2020


On 11/25/20, Bob van der Poel <bob at mellowood.ca> wrote:
>
> Ahha! Didn't know about os.pathsep. Seems simple enough to use that and be
> done with it.
>
> I'm just using str.split() just now. Is there a os.splitpath()? I don't see
> anything in the docs.

There are no platform standard rules to follow when splitting a path
list. A string split() on os.pathsep suffices. If you don't have a
special use for empty entries, you can filter the result with a list
comprehension, e.g. [p for p in (os.environ.get('MYPATH') or
default).split(os.pathsep) if p]. The `default` value here is for when
MYPATH isn't defined or has an empty-string value.


More information about the Python-list mailing list