3
UU/IT 08-01-29 | #3@ UU/IT What is Python? Dynamic, interpreted high-level language. Created in 1991 by Guido van Rossum. Design philosophy: Short development time is prioritized over excecution speed. Syntax similar to C++ or Java.

4
UU/IT 08-01-29 | #4@ UU/IT Facts about Python Portable, available for all common platforms. Python is Open Source and free to use, even for commercial applications. (Relatively) Easy to integrate with other languages, such as Java, C/C++, Fortran and.NET. Designed for multiple paradigms. Both object oriented and procedural programming are possible.

5
UU/IT 08-01-29 | #5@ UU/IT What is Python good for? Internet applications, good support for HTTP, FTP, SMTP and CGI. Integrating components written in a low-level language, “glue code”. Portable system tools, same commands on each platform. Compare with dir (Windows) and ls (Linux). Portable GUI:s. Database handling. Projects where time of development is more important than speed of execution.

6
UU/IT 08-01-29 | #6@ UU/IT What is Python not good for? Tasks where performance is critical. Such tasks can be implemented in C/C++ modules using tools such as SWIG (www.swig.org).

7
UU/IT 08-01-29 | #7@ UU/IT Python and VTK VTK is written in C++, but has bindings to Python, Java, Tcl... In this course, we will use VTK with Python.

8
UU/IT 08-01-29 | #8@ UU/IT The Python prompt Can be used to execute individual Python commands interactively. The prompt has a “memory” which is kept until the prompt is closed. Start the prompt by typing python in a terminal.

23
UU/IT 08-01-29 | #23@ UU/IT If-statements Note the indentation! In Python, indentation is used to control which block a statement belongs to. A colon indicates that a new block of code begins. >>> a = 10 >>> if a > 5:... print "The number is greater than 5"... The number is greater than 5

24
UU/IT 08-01-29 | #24@ UU/IT else >>> a = 10 >>> if a < 5:... print "a is less than 5"... else:... print "a is greater than or equal to 5"... a is greater than or equal to 5

25
UU/IT 08-01-29 | #25@ UU/IT Multiple choices Multiple choices are handled with elif. Many languages have a case-statement for handling multiple choices. This was deemed redundant by the Python developers. >>> a = 10 >>> if a == 1:... print "a is one"... elif a == 2:... print "a is two"... elif a == 3:... print "a is three"... else:... print "a is something else"... a is something else

28
UU/IT 08-01-29 | #28@ UU/IT Beyond the Python prompt The python prompt is not suited for larger programs. Python programs are stored in regular text files. Commonly the filenames end with.py, but this is not required.

29
UU/IT 08-01-29 | #29@ UU/IT Executing Python programs Python files are executed using the python command. The search path to this program must be set. On windows, this is set by the system variable PYTHONPATH.

30
UU/IT 08-01-29 | #30@ UU/IT Python is dynamically typed # -*- coding: utf-8 -*- # a refers to a number a = 1 print a, a.__class__ # a refers to a string a = "lkshjdglgv" print a, a.__class__ # a refers to a list a = [5, 2, 8, 5] print a, a.__class__ a.sort() ‏ # a refers to a number again a = 10 a.sort()‏ $> python dynamic_binding.py 10 lkshjdglgv [5, 2, 8, 5] Traceback (most recent call last): File "dynamic_binding.py", line 18, in a.sort()‏ AttributeError: 'int' object has no attribute 'sort' Duck Typing: "when I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

35
UU/IT 08-01-29 | #35@ UU/IT Order of arguments Problems with many arguments: Arguments must be given in the order given in the function defintion. # function_04.py def greeting(name="Unknown", age=20): print """Hello %s. You are %i years old.""" % (name, age)‏ greeting()‏ greeting("Pelle")‏ greeting(45) # Gives the wrong result $> python function_04.py Hello Unknown. You are 20 years old. Hello Pelle. You are 20 years old. Hello 45. You are 20 years old.

39
UU/IT 08-01-29 | #39@ UU/IT Modules When writing larger programs, it is not practical to keep all code in the same file. In python Modules offer a way to separate large programs into smaller units. Modules are also used to organize functions and variables into namespaces.

45
UU/IT 08-01-29 | #45@ UU/IT Private variables Python has limited support for private class variables. Variable names starting with two underscores (“__”) are considered private. If you really want to, it is still possible to access those variables from outside the class.

64
UU/IT 08-01-29 | #64@ UU/IT 7 basic VTK objects to render a scene vtkRenderWindow: manages a window on the display device vtkRenderer: coordinates the rendering process involving lights, cameras, and actors vtkLight: a source of light to illuminate the scene vtkCamera: defines the view position, focal point, etc. vtkActor: represents an object rendered in the scene, both its properties and position in the world coordinate system vtkProperty: defines the appearance properties of an actor including colour, transparency, and lighting properties such as specular and diffuse. Also representational properties like wireframe and solid surface vtkMapper: the geometric representation for an actor. More than one actor may refer to the same mapper