py2bat & license comment

arthurman at arthurman at
Wed Sep 27 17:21:07 CEST 2000

Hi, all

Some months back, on one of the mailing lists,
Michal at
posted some code to enable running a Python
script as a DOS BAT file under the
DOS shell, a la the Perl pl2bat utility.  I'd
barely started to learn Perl when
I (oh-so-thankfully) discovered Python, but I did
sort of miss pl2bat, so I was
tickled to see Michal's posting.  I decided to
take it one step further and
write my own little utility to automate adding
Michal's code to any Python
script.  The result is below.

Anent the licensing issue: in my current
incarnation as a lawyer (mercifully
to terminate in the not-too-distant future via
retirement), I don't feel
comfortable releasing even the trivial script
below without some license -- at
least enough to support a liability disclaimer.
On the other hand, I can see,
unfortunately, a "battle of the licenses"
emerging in the open source movement.
That ain't good.  The best compromise may be to
pick one and stick with it.  I'm
no expert in intellectual property law, but
BeOpen's license seems as good as any
to me.  So to set a good example ;-), I'm
eschewing the temptation to write my own
license and am adopting BeOpen's license for the
following "poor thing, but
mine own."  FWIW, I think a choice-of-law clause
is a pretty darn good idea.

Hope-some-find-it-useful-feeback-welcome-ly yours,


A. Robert Thurman
bobthurman at
"Two wrongs do not make a right -- however, three
lefts do."

                Copyright © 2000 A. Robert Thurman

Script for converting Python scripts to enable
them to run as *.BAT files
under Microsoft DOS/Windows.

pygobats is licensed to all users thereof under
the identical terms and
conditions as set forth in the license,
incorporated herein by this reference,
between and users of PythonLabs Python
v. 2.0, which terms may be
found at:

with the exception that the licensor of pygobats
is A. Robert Thurman,
PMB 264, 2274 So. 1300 East #G8, Salt Lake City,
UT 84106, whose name and
address are substituted for those of
in said license.

import sys, string

def Batify():
    """Primary function -- reads in script, adds
cruft, writes out as BAT"""
    if len(sys.argv) < 2:      # check for file
name presence on command line
        Bugout("Usage: 'python <file
name>'\n", 1)
    flname = sys.argv[1]
    if len(string.split(flname, '.')) >
1:           # strip file name suffix
        flname = string.split(flname, '.')[0]
        ifl = open(flname + '.py', 'r')
        Bugout('Cannot find %s%s\n' %
(flname, '.py'), 1)
        ofl = open(flname + '.bat', 'w')
        Bugout('Cannot open %s%s\n' %
(flname, '.bat'), 1)
    ofl.write('@echo off\n')             # Python
execution will skip this line
    ofl.write('REM = """\n')      # from here
python will parse these lines ...
    ofl.write('REM %s.bat from by
pygobats\n\n' % (flname, flname))
    ofl.write('python -x %s.bat\n' % flname)  # -
x switch skips script 1st line
    ofl.write('goto end\n')
# .... to here as a doc string
    while 1:                                 #
now add the whole Python script
        buf = ifl.readline()
        if not buf:
    ofl.write('\n\n"""\n')        # python thinks
this is another doc string --
    ofl.write(':end """\n') # and DOS shell ends
execution, having skipped rest
    Bugout('pygobats signing off -- conversion
completed.\n', 0)

def Bugout(msg, val):
    x = raw_input('Mash "Enter" to exit')

if __name__ == '__main__':

Sent via
Before you buy.

More information about the Python-list mailing list