2. Guide to Python in Civ IV: Basic Python

If you have some prior programming experience or have gone through GBM's lessons you know that the primary structure of programs involves functions and classes. Classes contain functions and variables and are used to organize ones that are related into 'objects' that can be accessed by calling the class and the variable/function together. I will give examples of this later, but for now it's simply important to know the structure of things.

One thing that's unique about Python when compared to most languages is that variables do not actually store data, but reference 'objects' (different concept from what we've already covered). In most other languages data is stored in memory and given a type (integer, string, etc.) and label (the name of the variable). In Python data is stored in memory as an object and the type is stored there, while variables simply REFER, or point to the location of that data in memory (known as pointers in other languages). What this means is that when you instantiate, or create a variable, you don't need to set a type, because the type is stored with the object itself and not the variable. There are also other things that differ from other languages when working with pointers instead of data containers, but those already experienced with programming will already know, and those who aren't won't need to know. ;) To keep things fairly simple (for me, mostly) I will simply refer to variables with normal variable terminology rather than treating them specially like the pointers they are.

Something important to remember in Python is that there is no use of brackets to denote encapsulation - everything is done through indentation. It's important to keep an eye on your indentation and make sure nothing is stray in your code. I like to delete all of the white space at the end of what I'm working with just to make sure nothing is screwed up.


Index

1. Guide to Python in Civ IV: Introduction
2. Guide to Python in Civ IV: Basic Python
3. Guide to Python in Civ IV: Classes in Python
4. Guide to Python in Civ IV: Python in Civ IV
5. Guide to Python in Civ IV: Iteration (Looping)
6. Guide to Python in Civ IV: Civ IV Function Assignment
7. Guide to Python in Civ IV: Creating a Unit in Civ IV
8. Guide to Python in Civ IV: Class Reference (by Locutus)
9. Further Class Reference (by Solver)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License