Python Forum

Full Version: sys.path.insert()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i inserted a path by doing sys.path.insert(0,mypath). how do i delete it?
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.
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)]