User-Friendly Program Launchers
Suppose, for just a moment, that you wish to ship Python programs to an audience that may be in the very early stages of evolving from computer user to computer programmer. Maybe you are shipping a Python application to nontechnical users; or perhaps you’re interested in shipping a set of cool Python demo programs on a Python book’s CD-ROM (see http://examples.oreilly.com/python2). Whatever the reason, some of the people who will use your software can’t be expected to do any more than click a mouse -- much less edit their system configuration files to set things like PATH and PYTHONPATH per your programs’ assumptions. Your software will have to configure itself.
Luckily, Python scripts can do that too. In the next two sections, we’re going to see two modules that aim to automatically launch programs with minimal assumptions about the environment on the host machine:
Launcher.pyis a library of tools for automatically configuring the shell environment in preparation for launching a Python script. It can be used to set required shell variables -- both the PATH system program search path (used to find the “python” executable), and the PYTHONPATH module search path (used to resolve imports within scripts). Because such variable settings made in a parent program are inherited by spawned child programs, this interface lets scripts preconfigure search paths for other scripts.LaunchBrowser.pyaims to portably locate and start an Internet browser program ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access