Land Plots Over Wtaer Plots - help with a code

All I'm saying it that there is no big mystery out there. You don't have to spend half a work week trying to get something as basic as indentation in order. In fact, you could spend half that time and learn the basics of any programming language. Including just about everything there is to know about indentation with Python.

So my point, then, is that you probably shouldn't be afraid of trying to learn new things. Like the absolutely minimal basics of something like Python - since you're working with it. You don't need to spend more than say 20 minutes getting all indentation in order for any Python merge, even if you don't know any actual programming. If you spend 20 hours :eek: unsuccessfully trying to do something this basic you're just wasting your time. (And in the end - other people's time.)

Wasting time and effort is pretty lame, especially if you keep wasting it. :rolleyes:

But all the best of luck with all your future efforts. I mean it. :goodjob: Just say the word if you're interested in learning how to do things, instead of asking for help where you could just solve it yourself. (I learned Python in a matter of weeks, and then I was doing the most advanced stuff I could imagine.:eek: And I knew nothing about it before I decided to not bang my head against the wall anymore...)
 
Indentation is used to organize code with Python. It not only makes the code easier to read (for the programmer) but is actually necessary for the interpreter program to understand what it is reading. Once the logic breaks down, the program breaks down.

So indentation divides code - basically different kinds of statements and definitions - or "commands" if you like - into "blocks". Blocks of code. Why? Because if you define something, then you need to tell the Python interpreter what lines are part of the definition. Because all of the code might not be.

The same goes for some types of statements, like if statements or different types of iteration statements. The important thing to know for a "merger" is only that every time a line of code ends with a colon, there is supposed to be new block of code following. And a new block mean that the indentation level goes up - one level.

This brings us to indentation levels. The first level - also known as __main__ - has no indentation. The next level is intended - but by how much? This is actually arbitrary, and this very fact would probably be a major cause for headache for any merger! Because one level can be represented by any number of "whitespace".

First rule: The amount of whitespace must be the same for the entire .py file (or "module"). Second rule: There are two types of whitespace commonly used for indentation; blank spaces and tabs. Its the number of whitespaces used that counts - not how many spaces they take up or how it looks in any given text/code editor!

So you basically can't mix and match blank space and tabs. Figure out what type of whitespace is used in the module your work is based upon - and how many whitespace of this type is used. Then you have to convert any code that you're importing (copy-pasting into the script or program) so that the indentation levels match - both with regard to what type of and how many whitespace is being used - and what indentation level the code belongs to.

This brings us back to the topic at hand: Indentation levels. Example of a class definition:
Code:
class ThisClass:
Class definitions are mostly found at the first level, so there would be no indentation. Add a function (or actually method, but this is not important) definition:
Code:
    def __init__(self, setting):
Three things to note right here:
  1. Since the first line (the class definition) ended with a colon, there should be a new block of code. This is achieved with indentation.
  2. Now is when I decide what whitespace I'm gonna use and how many instances of it. In this example I went with four times blank space - from now on this is the standard.
  3. This line also ends with a colon - meaning that there should be another block of code:
Code:
        self.default = None
This assignment statement is intended eight blank spaces and is thus a valid block of code (2 * 4). Since there never is a colon at the end of any assignment statement, the next line of code belongs to the same block. So it gets the same amount of indentation:
Code:
        if setting == None:
Opps, there is that colon again! An if statement always has to be followed by a new block of code:
Code:
            self.default = False
Now, for the sake of computer logic, we want to return to the previous indentation level. So we subtract four instances of blank space from the previous indentation level:
Code:
        else:
Another colon...
Code:
            self.default = setting
If we wanna define another method belonging to the same class - or level - as before we have to back up to the same indentation level as the first one (1 x 4):
Code:
    def thatMethod(self):
And so on... This is what our Python script could look like:
Spoiler :
Code:
class ThisClass:

    def __init__(self, setting):
        self.default = None
        if setting == None:
            self.default = False
        else:
            self.default = setting

    def thatMethod(self):
        print self.default
        if self.default > 1:
            return True
Spoiler :
(Programming is actually so much fun I have to stop myself before I actually finish an entire program. You should give it a try sometime!)

All this would of course only be obvious for a programmer - and it would pretty much take a Python programmer to realize the finer points of the use of indentation. But it would none-the-less be required knowledge for anyone trying to merge Python code!

(Blank lines mean nothing to the Python interpreter, by the way. This is really only a kind of typography I'm using to illustrate my example in a clearer manner. You can add or subtract as many blank lines you want!)

Take a look at some sample code you are working with - or have worked with in the past - and try to see the logic behind the various levels and blocks of code. You don't need to understand what any single line of code means or does, but you will see that it all adheres to the simple rules stated in this post.

Next time you merge any Python code, start with figuring out what the indentation levels are and how they are represented. Then do your out-most to follow this example in the entire file! (But be prepared that what you just did doens't necessarily apply in another Python module. You actually save time by checking this as your first order of business.)

edit: Another rule you should know about: The indentation level can never go up more than one level at the time! (It can drop any number of levels though, adhering to the rules of logic.)
 
I though I'd find a good link for you that explains indentation, but soon realized that its actually so basic knowledge that it isn't really even covered as a topic of its own. Because tutorials and textbooks are written for people trying to learn programming, not merging...

And I just saved myself a lot of time and effort, since I will be able to link to my post next time someone is asking for help cleaning up indentation. Because there is no reason they shouldn't at least try to fix it themselves.
 
awesome a link would be very nice,
Ah, I didn't find one so I wrote the tutorial myself. :p

But all you need to learn about Python is in this textbook. Its actually available for free online.

Also, the official Python tutorial will learn you pretty much everything you ever need to know.

But these sources of course teach you nothing about modding. Once you know Python there are some tutorial in the Modiki for this though.
 
Back
Top Bottom