Please help me understand the function sys.path.extend

I have tried to seach online but cound not find the details of sys.path.extend function.
The actual script is below:
``
sys.path.extend([‘C:\\Users\Name\\My Software\\PythonHighstopEval\\used_libraries’])

``
Thanks in advance.

  • Please use triple (not double) backticks for the code to show properly.
  • Your code contains an invalid Unicode escape sequence inside the string: \N — You probably wanted an escaped backslash: \\N

extend is a method list.extend(), not a function:

In your case you are appending just a single item (single string) so it would be more clear and efficient to use sys.path.append() instead.

1 Like

Do you know what sys.path is?

  • It is a list containing directories that the import command will search for modules to import.

Do you know what the extend method does for lists?

  • It takes a list of items and adds each of them to the first list.

So sys.path.extend() takes what should be a list of directories, and adds each of them to the import search path.

1 Like