Python Advanced Help

Peter Otten __peter__ at web.de
Tue Mar 15 14:16:21 EDT 2016


Luke Charlton wrote:

> Okay, So basically I created a python script around 1 year ago to grab an
> explain_plan from a Greenplum system (Normal SQL) and change it around and
> explain each step/section, the thing is, I've came back to the python code
> and I don't understand anything of what it's doing (the code
> specifically). The Script does work but I just want to explain each
> section to myself and understand it a bit more as I've forgot Python. This
> means putting comments/notes in next to each section to explain it but
> hidden so it doesn't show up when ran, so using the # commenting out #.
> 
> 
> The aim of the script is to make the explain_plan understandable because
> it comes out all garbled, so i've turned it upside down because thats how
> you read it, it goes from bottom to top instead of the default top to
> bottom. I've put step 1/2 in etc... but I want to know in the code what
> does what and where etc so I can then expand on the explanation of the
> explain_plan.
> 
> Code (Python) - http://pastebin.com/sVhW34fc (This is the one I'm trying
> to understand) Before & After of an Explain_Plan in SQL Greenplum -
> http://pastebin.com/81kNWVcy
> 
> What we're aiming for (Teradatas Explain_Plan) -
> http://pastebin.com/Nm4g12B3

You are about to learn a valuable lesson early in your programming career:

Throw away convoluted code that while trying to solve a simple problem is 
hard to follow.

Instead take the time necessary to read an introductory text on Python. Then 
describe the problem you want to solve in plain English. 

Finally translate the English into Python. Use descriptive variable names. 
If you run into problems that you cannot solve yourself come back here or 
ask on the tutor mailing list.

I expect that the resulting script will need only the input file and one 
list to reverse its lines, but no temporary files.

You may even be able to still understand it next year ;)




More information about the Python-list mailing list