Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29476
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: 'indent'ing Python in windows bat |
| Date | 2012-09-19 11:22 +0200 |
| Organization | A newly installed InterNetNews server |
| Message-ID | <k3c2st$l6l$1@r03.glglgl.gl> (permalink) |
| References | <mailman.3021.1347928001.27097.python-list@python.org> <5057C990.8080809@invtools.com> <k38vl8$u02$2@ger.gmane.org> <505803A9.4000409@davea.name> <mailman.870.1347973403.27098.python-list@python.org> |
Am 18.09.2012 15:03 schrieb David Smith:
> I COULD break down each batch file and write dozens of mini python
> scripts to be called. I already have a few, too. Efficiency? Speed is
> bad, but these are bat files, after all. The cost of trying to work with
> a multitude of small files is high, though, and I realized I had better
> go to a mix.
In order to achieve this, it might be very useful to either have a
module for each (bigger) part to be achieved which you can call with
python -m modulename arg1 arg2 arg3
and putting the Python code into modulename.py.
Or you have one big "interpreter" which works this way:
class Cmd(object):
"""
Command collector
"""
def __init__(self):
self.cmds = {}
def cmd(self, f):
# register a function
self.cmds[f.__name__] = f
return f
def main(self):
import sys
sys.exit(self.cmds[sys.argv[1]](*sys.argv[2:]))
cmd = Cmd()
@cmd.cmd
def cmd1(arg1, arg2):
do_stuff()
...
return 1 # error -> exit()
@cmd.cmd
def cmd2():
...
if __name__ == '__main__':
cmd.main()
This is suitable for many small things and can be used this way:
bat cmds
python -m thismodule cmd1 a b
other bat cmds
python -m thismodule cmd2
...
HTH,
Thomas
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: 'indent'ing Python in windows bat David Smith <davids@invtools.com> - 2012-09-18 09:03 -0400
Re: 'indent'ing Python in windows bat Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-19 11:22 +0200
Re: Re: 'indent'ing Python in windows bat David Smith <davids@invtools.com> - 2012-09-19 08:27 -0400
Re: 'indent'ing Python in windows bat Terry Reedy <tjreedy@udel.edu> - 2012-09-19 14:18 -0400
Re: Re: 'indent'ing Python in windows bat David Smith <davids@invtools.com> - 2012-09-19 16:09 -0400
csiph-web