Console with Blender/Python

Objectives

a Familiarize youself with the console and the interactive Python interpreter in Blender.

Instructions

Tasks:
  1. Which version has the system-used Python interpreter?
  2. Which paths are searched by the Python interpreter?
  3. Print the sys-modules’s documentation.
  4. What is the difference between the methods »version« and »version_info«
  5. Where is your version of Blender located??
  6. 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 version 2.68 from the website http://www.blender.org/download. Note the installation and start instructions on the Blender website!

Find/start console

../../_images/b.png

Download the following blend file:

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:

../../_images/console-start.png

In both cases you get the following result:

../../_images/console.png

System info

../../_images/p.png

After the prompt: >>> you can type in instructions/commands. You finish the input with the enter key.

The output looks about this:

../../_images/dir.png

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.

The sys-module

../../_images/p.png

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.

>>>import sys

After the import of sys, dir() shows you a longer list:

../../_images/dir1.png

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.

../../_images/dir2.png

Output with print

../../_images/p.png

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.

../../_images/platform.png

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.

../../_images/encoding.png

Everything and more as a video clip