Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sys.path.insert()
#1
i inserted a path by doing sys.path.insert(0,mypath). how do i delete it?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
Reply
#3
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)]
Skaperen likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,149 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,670 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  Insert using psycopg giving syntax error near "INSERT INTO" olgethorpe 4 15,496 Jul-21-2017, 07:39 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020