|Familiarize youself with the console and the interactive Python interpreter in Blender.|
- Which version has the system-used Python interpreter?
- Which paths are searched by the Python interpreter?
- Print the sys-modules's documentation.
- What is the difference between the methods »version« and »version_info«
- Where is your version of Blender located??
- What happens if you type in Python the command: import this? Discuss the output in a team or in twos!
Install the interpreter
For the work with Python you have to install software - Python interpreter. In the course we use a special form of Python, because:
- we want to show the results at the same time in a 3D-World,
- all users should work with the same version,
- operating system-specific questions should stay in the background and Python the focus of attention.
- the 3D-functions of Blender should be of interest only as far as necessary.
Blender is the software which is used in the course/competition. Download the newest version (2015: 2.76) from the website http://www.blender.org/download. Note the installation and start instructions on the Blender website!
Download the following blend file:
|download:||Blender file with opened »console window«|
and open it over the File-Open dialog or a double click, when the file extension .blend is linked with the program Blender.
Alternatively you can switch on to the console directly:
In both cases you get the following result:
After the prompt: >>> you can type in instructions/commands. You finish the input with the enter key.
The output looks about this:
You get a list with various names. The list is limited by square brackets and contains entries separated by commas. All names which start and end with »__« are Python system variables. You shouldn't use this notation for own names.
Programs are often very extensive, therefore the programs for special tasks are divided into separate modules or files. Python is modular, too. Additional functionality can be added to your Python program with the import function.
After the import of sys, dir() shows you a longer list:
Which functions offers the sys-module? Enter the the name of the module into the brackets, to get more information about it. With that you can get a first overview over a module.
Output with print
The universal output function is print. Because platform is defined in the module sys, the dot notation is used for a clear call. Like a track connects the train stations, the point connects the single names to a correct path. And now we are already midst in the object-oriented programming.
If the name a function/method, you have to add a pair of brackets to get the return-value. The first call in the picture returns only the method-name in a »strange packaging«. The second call adds a pair of brackets and gets the answer, in our case the description of the operation system that we use.