![]() |
sys.path.insert() - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: sys.path.insert() (/thread-33862.html) |
sys.path.insert() - Skaperen - Jun-02-2021 i inserted a path by doing sys.path.insert(0,mypath) . how do i delete it?
RE: sys.path.insert() - bowlofred - Jun-03-2021 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.
RE: sys.path.insert() - Gribouillis - Jun-03-2021 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)] |