PageRenderTime 46ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/python/class/runme.py

#
Python | 51 lines | 25 code | 17 blank | 9 comment | 1 complexity | 4288af82dd97fb39d0b9b18431f88be5 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: runme.py
  2. # This file illustrates the proxy class C++ interface generated
  3. # by SWIG.
  4. import example
  5. # ----- Object creation -----
  6. print "Creating some objects:"
  7. c = example.Circle(10)
  8. print " Created circle", c
  9. s = example.Square(10)
  10. print " Created square", s
  11. # ----- Access a static member -----
  12. print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
  13. # ----- Member data access -----
  14. # Set the location of the object
  15. c.x = 20
  16. c.y = 30
  17. s.x = -10
  18. s.y = 5
  19. print "\nHere is their current position:"
  20. print " Circle = (%f, %f)" % (c.x,c.y)
  21. print " Square = (%f, %f)" % (s.x,s.y)
  22. # ----- Call some methods -----
  23. print "\nHere are some properties of the shapes:"
  24. for o in [c,s]:
  25. print " ", o
  26. print " area = ", o.area()
  27. print " perimeter = ", o.perimeter()
  28. print "\nGuess I'll clean up now"
  29. # Note: this invokes the virtual destructor
  30. del c
  31. del s
  32. s = 3
  33. print example.cvar.Shape_nshapes,"shapes remain"
  34. print "Goodbye"