Graphics Reference
In-Depth Information
Likeallwindowtypes,thetexteditorisaccessedthroughtheEditorTypemenuintheheaderofanywindow
area. You can create a new file by clicking the New button in the header, as shown in Figure 12-5 .
Figure 12-5 Creating a new file in the Text Editor
The Blender text editor is a powerful editor with a variety of features for Python coding. For Blender Python
programming, this will likely be your starting point and might be the only editor you ever need.
To see how easy it is to run a Python script from the text editor, type the line print("Hello World")
into the text editor window. Run the code by pressing Alt+P or by clicking the Run Script button on the header.
Check the Blender console to see the output.
You'lluseBlender'sPythonConsolealotwhenyoudoPythonscripting.Itiswhereyouwillgetmostofthe
feedback you need for debugging, among other things.
Thus far in this chapter, you've learned enough about accessing the Python interpreter to get started with
scripting. Now all you need to know is how to write Python code! The rest of this chapter is devoted to a quick
overview of basic Python syntax.
Understanding Python Syntax
Python is similar to Perl and other scripting languages in that it has a procedural syntax that is augmented by
object-oriented functionality. This means that Python programs execute in a step-by-step (procedural) way, us-
ing loops and conditionals, and accessing object data by using methods defined for classes. There are three fun-
damental things that you need to know in order to use Python: how individual units of data are represented and
accessed,howtheoverallproceduralflowofaprogramisdetermined,andhowtoworkwithclassesandobjects
so you can understand and use an API such as the Blender-Python API.
Data Types and Structures
Python has several built-in basic data types. Each data type has its own way of interacting with operators and
has specific ways in which its information can be accessed. In this section, you'll learn about the most com-
monly used data types, which are the following:
Integers Integers ( int ) are numbers that can be represented without fractions or decimal points. Positive in-
tegers are sometimes referred to as natural numbers or counting numbers , but integers can also be negative.
Integers are often used to iterate over lists or to identify unique entities.
Floating-Point Numbers Floating-point numbers ( float ) are numbers that include a decimal point. They
behave as an approximation of real numbers and are the appropriate data type to use when you need to work
with real numbers.
Boolean Values Boolean values ( bool ) are true or false values. They take the value True or False .
Strings Strings ( str ) are sequences of characters. When you want to work with words or text, str is the
data type to use.
 
 
Search WWH ::




Custom Search