=========================== Console with Blender/Python =========================== .. index:: console in Blender .. |a| image:: /images/all/console/console-100.png :width: 100px Objectives ========== .. tabularcolumns:: | c | l | :border: none +-------+-------------------------------------------------------------------------+ | |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 ------------------ .. image:: /images/all/console/b.png :width: 32px 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: .. image:: /images/all/console/console-start.png In both cases you get the following result: .. image:: /images/all/console/console.png System info ----------- .. image:: /images/all/console/p.png :width: 32px After the prompt: **>>>** you can type in instructions/commands. You finish the input with the enter key. The output looks about this: .. image:: /images/all/console/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 ---------------- .. image:: /images/all/console/p.png :width: 32px 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: .. image:: /images/all/console/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. .. image:: /images/all/console/dir2.png Output with print ----------------- .. image:: /images/all/console/p.png :width: 32px 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. .. image:: /images/all/console/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. .. image:: /images/all/console/encoding.png Everything and more as a video clip --------------------------------- .. raw:: html