Jun-02-2021, 11:40 PM
Jun-03-2021, 01:46 AM
sys.path is just a list. So you can manipulate it like any other list. You can remove elements by index or name.
sys.path.remove('/path/to/wherever')
would be one method.Jun-03-2021, 06:49 AM
You could also mark the inserted items by giving them a specific type
class MyStr(str): __slots__ = () sys.path.insert(0, MyStr('spam')) ... # later sys.path[:] = [x for x in sys.path if not isinstance(x, MyStr)]