Hikki
Hikki

Reputation: 524

Running python functions from anywhere in command line

So, I was following this tutorial on Youtube. This person is running python commands from the shell.

-TLDR;

He has a function called nfe(args1, args2...) in a notes.py file in some directory.

However, he is able to call the kalles-Mackbook-Pro:~ kalle$ nfe args... from his shell (on his mac)

How?

Upvotes: 1

Views: 196

Answers (1)

a_guest
a_guest

Reputation: 36339

You can place an executable nfe on your PATH with the following content:

#!/bin/usr/python

import sys
sys.path.insert(0, '/path/to/notes/')

from notes import nfe

sys.exit(nfe(*sys.args[1:]))

This process can be automated by creating a package and registering console-script entry points:

setup(
    ...,
    entry_points={
        'console_scripts': [
            'nfe = my_package.notes:nfe',
        ]
    }
)

Upvotes: 3

Related Questions