Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29476
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!gegeweb.org!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| 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 | Wed, 19 Sep 2012 11:22:32 +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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 Hamster/2.1.0.11 |
| In-Reply-To | <mailman.870.1347973403.27098.python-list@python.org> |
| Lines | 58 |
| NNTP-Posting-Date | 19 Sep 2012 11:30:02 CEST |
| NNTP-Posting-Host | 043bc2bb.newsspool1.arcor-online.net |
| X-Trace | DXC=m@N>LNTSamR5TOT9_N5i<Vic==]BZ:af^4Fo<]lROoRQnkgeX?EC@@P[K;=GU^@eiVK8FCa6^2FWROLF_]FfFg8_5Ibl;fn=T0T |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.python:29476 |
Show key headers only | View raw
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