Graphics Reference
In-Depth Information
>>> a = 5
>>> a.__doc_
Modules
One of the main benefits of working in an OOP environment is that classes created by other people can be
easily used by anyone who knows the API for the classes. It should not be necessary to see the actual code of
the class definition in order to work with a class; all you should need is to know what attributes the object has,
what methods are defined for the class, and what the methods return. In principle, you should be able to ignore
everything else about how the classes and methods are specifically implemented.
To use classes defined by other people, you need to import the module in which the class is defined. Any
Python script can be a module, and any class defined in a script can be imported into another script in this way.
Modulesareimportedbyusing import modulename atthebeginningofthescriptinwhichyouwanttouse
theimportedclasses.Whenthisisdone,classesfromthemodulecanbeused,butitisnecessarytoprefacecalls
to the class with the module name, as in modulename.classname . To use the class name without having
to always append the module name, youmust import the class from the module byusing from modulename
import classname . A common shortcut that can be used when the module does not contain an unwieldy
number of classes is from modulename import * , which imports all classes from the module.
You will use this kind of construction a lot when working in the Blender-Python environment, because most
of the classes you will be working with come from Blender-related modules enumerated in the API. In the next
chapter,youwillgetfamiliarwiththeAPIandlearnhowtouseittoaccesstheinformationyouneedaboutyour
3D assets in the Python environment.
The Bottom Line
Become familiar with the basics of the Python language. Python is a widely used language for scripting in
many different application areas. It is known for its ease of use, readability, and speed of development.
Master It Make sure that you have a good reference handy for Python syntax. In this chapter, I listed
several good topics you should consider buying. Use a Google search to find some more good online
resources to quickly look up Python operators and data types. Python has a number of great tools for
workingwithdatastructureslikestrings,lists,anddictionaries.Readuponthese,andlearnhowtowork
with list functions. What is the difference between the append() and extend() list functions? How
can you reverse the ordering of a list?
Work with the Blender Python scripting environment. The simplest way to access Python directly is
through the Python Console built into Blender. In this shell environment, you can execute individual com-
mands and perform introspection on variables. Python can also be used by writing scripts in Blender's text
editor window and viewing the results in the System Console or Terminal.
Master It In this chapter, you learned that you cannot concatenate a string and an integer by using the
+ operator. Likewise, you cannot add a string numerically. In some cases, however, numerical data may
be input (for example, in a form) as a string type. Study the references you searched for in the previous
Master It exercise to learn about type casting in Python and find out how you would convert the string
"5" into an integer that can be added to another.
Search WWH ::




Custom Search