[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: script-with-language-extension



Matthew Palmer <mpalmer@debian.org> writes:

> So someone's using a single file as both a library and a stand-alone
> program. Damned silly idea.

Not so silly; a Python module can be useful both as a main program and
as a re-useable component in other programs. The well-known Python idiom
of testing ‘if __name__ == '__main__'’ is commonly used to make a module
that can be used in either way.

> Stick zynjacku.py in a proper library path somewhere, and write a
> little shim wrapper to stick in /usr/bin that calls zynjacku as it
> expects to be called.

Yes, that's one way to do it, and quite valid. It does, though, involve
creating that shim separately after installing the distribution.

IIUC, the ‘entry_points’ facility (of the third-party ‘pkg_resources’
module) is another way, that allows the program file to be created
automatically, such that when run it will invoke a specified function,
along with the rest of the distribution's installation process.

-- 
 \                         “I'm a great lover, I'll bet.” —Emo Philips |
  `\                                                                   |
_o__)                                                                  |
Ben Finney


Reply to: