How to append multiple Paths to PYTHONPATH programmatically

sys.path.append('/home/user/test1','/home/user/test2', ...) does not work because append() function can take only 1 argument.

What you could use instead is:

import sys
sys.path += ['/home/user/test1','/home/user/test2','/home/user/test3','/home/kahmed/test4']

Try this:

import sys
sys.path.append('/home/user/')
from test1.common.api import GenericAPI

It is not recommended, but will maybe do what you meant to do? Because I guess your files are not in the folder /home/user/test1/test1/common/api/ ...

Given a python path of ["a", "b", "c"], trying to import a.b.c will look in a/a/b/c, then b/a/b/c and c/a/b/c. However, NOT in a/b/c. There is no matching of the module name starting with a and the python path ending with a and then leaving out one of the as. It strictly is path + module, not part-of-path + part-of-module.

Since your question is about "multiple paths", does a single path work for you yet? Doesn't seem so...