Q:

run import.py with sys parameters

I am debugging code, which has this line:
run('python /home/some_user/some_repo/pyflights/usertools/import.py /home/some_user/some_repo/pyflights/config/index_import.conf flights.map --import')

run - is some analog of os.system
So, I want to run this code without using run function. I need to import my import.py file and run it with sys.args. But how can I do this? 
from some_repo.pyflights.usertools import import

A:

There is no way to import import because import is a keyword. Moreover, importing a python file is different from running a script because most scripts have a section
if __name__ == '__main__':
    ....

When the program is running as a script, the variable __name__ has value __main__.
If you are ready to call a subprocess, you can use
`subprocess.call(...)`

Edit: actually, you can import import like so
from importlib import import_module
mod = import_module('import')

however it won't have the same effect as calling the script. Notice that the script probably uses sys.argv, and this must be addressed too.
Edit: here is an ersatz that you can try if you really don't want a subprocess. I don't guarantee it will work
import shlex
import sys
import types

def run(args):
    """Runs a python program with arguments within the current process.

    Arguments:
        @args: a sequence of arguments, the first one must be the file path to the python program

    This is not guaranteed to work because the current process and the
    executed script could modify the python running environment in incompatible ways.
    """
    old_main, sys.modules['__main__'] = sys.modules['__main__'], types.ModuleType('__main__')
    old_argv, sys.argv = sys.argv, list(args)
    try:
        with open(sys.argv[0]) as infile:
            source = infile.read()
        exec(source, sys.modules['__main__'].__dict__)
    except SystemExit as exc:
        if exc.code:
            raise RuntimeError('run() failed with code %d' % exc.code)
    finally:
        sys.argv, sys.modules['__main__'] = old_argv, old_main

command = '/home/some_user/some_repo/pyflights/usertools/import.py /home/some_user/some_repo/pyflights/config/index_import.conf flights.map --import'
run(shlex.split(command))

