[Tutor] Script to generate statements
Hugo Arts
hugo.yoshi at gmail.com
Fri Mar 15 22:03:13 CET 2013
On Fri, Mar 15, 2013 at 7:42 PM, Charles Leviton
<charles.leviton at gmail.com>wrote:
> I was recently given this task. it's a very IBM mainframe specific task
> so I'm not sure how to find equivalent terms in another environment. I
> will just use the mainframe terminology and hopefully y'all can figure out
> what I mean.
>
> Given a list of DBRM members create a JCL which has a series of bind
> statements for each DBRM.
>
> This is the tack I took. I have 3 input files
> a_ contains the fixed part of the JCL
> b_ contains the template for the bind statement.
> c_ contains the list of DBRMs
>
>
> This is the script I came up with...Would you critique it and let me know
> how I could have done it better?
> #create a series of bind statements
> fo = open('i:/text/jclout.txt', 'w')
> fi = open('i:/text/bindjclfirstpart.txt','rU')
> fibindjclvar = open('i:/text/bindjclvariable.txt','rU')
> filistofdbrms= open('i:/text/bindjcldbrmlist.txt','rU')
>
> varlines =[]
> varlines = fibindjclvar.readlines()
> for line in fi: #write out all the lines in the first part of JCL
> fo.write(line)
> fo.write('\n')
> varline = ''
> for dbrm in filistofdbrms:
> fo.write('\n')
> for index in range(0,9):
> if varlines[index].find('member') > 0:
> varline = varlines[index] + '('+ dbrm + ')' + ' -'
> else:
> varline = varlines[index]
> fo.write(varline)
>
> fo.close()
> fi.close()
> fibindjclvar.close()
> filistofdbrms.close()
>
> The "variable" part of the bind statement is where I have to include the
> DBRM name. I look for the word 'member' in the template.
> Template looks like this (content of bindjclvariable.txt)
> BIND PACKAGE(PROD) -
> MEMBER
> OWNER(PRODOWNR) -
> QUALIFIER(PRODTBLS) -
> ISOLATION(CS) -
> EXPLAIN(YES) -
> ACTION(REPLACE) -
> CURRENTDATA(YES) -
> VALIDATE(BIND)
>
> Thanks!
>
I have a few comments
* Does the script work? If yes, I'd say it's probably fine. Pretty short so
easy to understand whatever you do, and I see no obviously crazy broken
shit in there. I don't much like 'fi' and 'fo' for variable names because I
have no idea what it means, but it's not a huge issue in a script this
small. If anything, I'd suggest more descriptive variable names and just a
tad more use of underscores in them to make it easier on the eyes. Google
PEP 8 and check it out, it's the python style guide.
* I have no clue what DBRM or JCL are, and what a bind statement is.
Ideally, if you could give us some examples of what your input and output
looks like, I have a much better idea of what the script is trying to do.
* Not knowing what version of python you have greatly limits the amount of
useful advice I can give you. More modern versions support stuff like with
statements to simplify file handling and the str.format function which may
be very useful in your template (you could also use % style formatting,
perhaps?). But if you're still on 2.5, which wouldn't surprise me on a big
mainframe, you don't have the cool stuff yet.
Like I said in the first point though, the script is very small and
everything looks quite reasonable. It seems readable enough *if* you know
what kind of input and output date it's dealing with.
HTH,
Hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130315/93bd8c3a/attachment-0001.html>
More information about the Tutor
mailing list