Merge branch 'yazug-python_examples_pep8_whitespace_cleanup'
* yazug-python_examples_pep8_whitespace_cleanup: Fixup 2 additional whitespace warnings pep8 found Add pep8 check for Examples/python autopep8 cleanup of Examples/python whitespace
This commit is contained in:
commit
21aef52194
41 changed files with 280 additions and 326 deletions
|
|
@ -66,6 +66,9 @@ LIBCRYPT = @LIBCRYPT@
|
||||||
SYSLIBS = $(LIBM) $(LIBC) $(LIBCRYPT)
|
SYSLIBS = $(LIBM) $(LIBC) $(LIBCRYPT)
|
||||||
LIBPREFIX =
|
LIBPREFIX =
|
||||||
|
|
||||||
|
PEP8 = @PEP8@
|
||||||
|
PEP8_FLAGS = --ignore=E402,E501,E30,W291,W391
|
||||||
|
|
||||||
# RUNTOOL is for use with runtime tools, eg set it to valgrind
|
# RUNTOOL is for use with runtime tools, eg set it to valgrind
|
||||||
RUNTOOL =
|
RUNTOOL =
|
||||||
# COMPILETOOL is a way to run the compiler under another tool, or more commonly just to stop the compiler executing
|
# COMPILETOOL is a way to run the compiler under another tool, or more commonly just to stop the compiler executing
|
||||||
|
|
@ -372,7 +375,7 @@ endif
|
||||||
|
|
||||||
PY2TO3 = 2to3 `2to3 -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'`
|
PY2TO3 = 2to3 `2to3 -l | grep -v -E "Available|import$$" | awk '{print "-f "$$0}'`
|
||||||
|
|
||||||
python_run: $(PYSCRIPT)
|
python_run: $(PYSCRIPT) python_check
|
||||||
export PYTHONPATH=".:$$PYTHONPATH"; \
|
export PYTHONPATH=".:$$PYTHONPATH"; \
|
||||||
$(RUNTOOL) $(PYTHON) $(PYSCRIPT) $(RUNPIPE)
|
$(RUNTOOL) $(PYTHON) $(PYSCRIPT) $(RUNPIPE)
|
||||||
|
|
||||||
|
|
@ -385,6 +388,16 @@ $(RUNME)3.py: $(SRCDIR)$(RUNME).py
|
||||||
cp $< $@
|
cp $< $@
|
||||||
$(PY2TO3) -w $@ >/dev/null 2>&1
|
$(PY2TO3) -w $@ >/dev/null 2>&1
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
# Run Python pep8 if it exists
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
python_check: $(PYSCRIPT)
|
||||||
|
+if [ -n "$(PEP8)" ]; then \
|
||||||
|
$(PEP8) $(PEP8_FLAGS) $(PYSCRIPT) || true;\
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
# Version display
|
# Version display
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,16 @@
|
||||||
|
|
||||||
# This file illustrates the cross language polymorphism using directors.
|
# This file illustrates the cross language polymorphism using directors.
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
|
|
||||||
class PyCallback(example.Callback):
|
class PyCallback(example.Callback):
|
||||||
def __init__(self):
|
|
||||||
example.Callback.__init__(self)
|
def __init__(self):
|
||||||
def run(self):
|
example.Callback.__init__(self)
|
||||||
print "PyCallback.run()"
|
|
||||||
|
def run(self):
|
||||||
|
print "PyCallback.run()"
|
||||||
|
|
||||||
# Create an Caller instance
|
# Create an Caller instance
|
||||||
|
|
||||||
|
|
@ -25,7 +27,7 @@ callback = example.Callback()
|
||||||
callback.thisown = 0
|
callback.thisown = 0
|
||||||
caller.setCallback(callback)
|
caller.setCallback(callback)
|
||||||
caller.call()
|
caller.call()
|
||||||
caller.delCallback();
|
caller.delCallback()
|
||||||
|
|
||||||
print
|
print
|
||||||
print "Adding and calling a Python callback"
|
print "Adding and calling a Python callback"
|
||||||
|
|
@ -53,4 +55,3 @@ caller.delCallback()
|
||||||
|
|
||||||
print
|
print
|
||||||
print "python exit"
|
print "python exit"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# This file illustrates the proxy class C++ interface generated
|
# This file illustrates the proxy class C++ interface generated
|
||||||
# by SWIG.
|
# by SWIG.
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
# ----- Object creation -----
|
# ----- Object creation -----
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@ print " Created square", s
|
||||||
|
|
||||||
# ----- Access a static member -----
|
# ----- Access a static member -----
|
||||||
|
|
||||||
print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
|
print "\nA total of", example.cvar.Shape_nshapes, "shapes were created"
|
||||||
|
|
||||||
# ----- Member data access -----
|
# ----- Member data access -----
|
||||||
|
|
||||||
|
|
@ -28,16 +28,16 @@ s.x = -10
|
||||||
s.y = 5
|
s.y = 5
|
||||||
|
|
||||||
print "\nHere is their current position:"
|
print "\nHere is their current position:"
|
||||||
print " Circle = (%f, %f)" % (c.x,c.y)
|
print " Circle = (%f, %f)" % (c.x, c.y)
|
||||||
print " Square = (%f, %f)" % (s.x,s.y)
|
print " Square = (%f, %f)" % (s.x, s.y)
|
||||||
|
|
||||||
# ----- Call some methods -----
|
# ----- Call some methods -----
|
||||||
|
|
||||||
print "\nHere are some properties of the shapes:"
|
print "\nHere are some properties of the shapes:"
|
||||||
for o in [c,s]:
|
for o in [c, s]:
|
||||||
print " ", o
|
print " ", o
|
||||||
print " area = ", o.area()
|
print " area = ", o.area()
|
||||||
print " perimeter = ", o.perimeter()
|
print " perimeter = ", o.perimeter()
|
||||||
# prevent o from holding a reference to the last object looked at
|
# prevent o from holding a reference to the last object looked at
|
||||||
o = None
|
o = None
|
||||||
|
|
||||||
|
|
@ -47,5 +47,5 @@ print "\nGuess I'll clean up now"
|
||||||
del c
|
del c
|
||||||
del s
|
del s
|
||||||
|
|
||||||
print example.cvar.Shape_nshapes,"shapes remain"
|
print example.cvar.Shape_nshapes, "shapes remain"
|
||||||
print "Goodbye"
|
print "Goodbye"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
print "ICONST =", example.ICONST, "(should be 42)"
|
print "ICONST =", example.ICONST, "(should be 42)"
|
||||||
print "FCONST =", example.FCONST, "(should be 2.1828)"
|
print "FCONST =", example.FCONST, "(should be 2.1828)"
|
||||||
|
|
@ -8,7 +8,7 @@ print "CCONST =", example.CCONST, "(should be 'x')"
|
||||||
print "CCONST2 =", example.CCONST2, "(this should be on a new line)"
|
print "CCONST2 =", example.CCONST2, "(this should be on a new line)"
|
||||||
print "SCONST =", example.SCONST, "(should be 'Hello World')"
|
print "SCONST =", example.SCONST, "(should be 'Hello World')"
|
||||||
print "SCONST2 =", example.SCONST2, "(should be '\"Hello World\"')"
|
print "SCONST2 =", example.SCONST2, "(should be '\"Hello World\"')"
|
||||||
print "EXPR =", example.EXPR, "(should be 48.5484)"
|
print "EXPR =", example.EXPR, "(should be 48.5484)"
|
||||||
print "iconst =", example.iconst, "(should be 37)"
|
print "iconst =", example.iconst, "(should be 37)"
|
||||||
print "fconst =", example.fconst, "(should be 3.14)"
|
print "fconst =", example.fconst, "(should be 3.14)"
|
||||||
|
|
||||||
|
|
@ -21,7 +21,3 @@ try:
|
||||||
print "FOO = ", example.FOO, "(Arg! This shouldn't print anything)"
|
print "FOO = ", example.FOO, "(Arg! This shouldn't print anything)"
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print "FOO isn't defined (good)"
|
print "FOO isn't defined (good)"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
# Call our gcd() function
|
# Call our gcd() function
|
||||||
|
|
||||||
x = 42
|
x = 42
|
||||||
y = 105
|
y = 105
|
||||||
g = example.gcd(x,y)
|
g = example.gcd(x, y)
|
||||||
print "The gcd of %d and %d is %d" % (x,y,g)
|
print "The gcd of %d and %d is %d" % (x, y, g)
|
||||||
|
|
||||||
# Manipulate the Foo global variable
|
# Manipulate the Foo global variable
|
||||||
|
|
||||||
|
|
@ -19,12 +19,3 @@ example.cvar.Foo = 3.1415926
|
||||||
|
|
||||||
# See if the change took effect
|
# See if the change took effect
|
||||||
print "Foo = ", example.cvar.Foo
|
print "Foo = ", example.cvar.Foo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
print "example.Foo.bar.__doc__ =", repr(example.Foo.bar.__doc__), "(Should be 'No comment')"
|
print "example.Foo.bar.__doc__ =", repr(example.Foo.bar.__doc__), "(Should be 'No comment')"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ print " Foo_LUDICROUS =", example.Foo.LUDICROUS
|
||||||
print "\nTesting use of enums with functions\n"
|
print "\nTesting use of enums with functions\n"
|
||||||
|
|
||||||
example.enum_test(example.RED, example.Foo.IMPULSE)
|
example.enum_test(example.RED, example.Foo.IMPULSE)
|
||||||
example.enum_test(example.BLUE, example.Foo.WARP)
|
example.enum_test(example.BLUE, example.Foo.WARP)
|
||||||
example.enum_test(example.GREEN, example.Foo.LUDICROUS)
|
example.enum_test(example.GREEN, example.Foo.LUDICROUS)
|
||||||
example.enum_test(1234,5678)
|
example.enum_test(1234, 5678)
|
||||||
|
|
||||||
print "\nTesting use of enum with class method"
|
print "\nTesting use of enum with class method"
|
||||||
f = example.Foo()
|
f = example.Foo()
|
||||||
|
|
@ -28,4 +28,3 @@ f = example.Foo()
|
||||||
f.enum_test(example.Foo.IMPULSE)
|
f.enum_test(example.Foo.IMPULSE)
|
||||||
f.enum_test(example.Foo.WARP)
|
f.enum_test(example.Foo.WARP)
|
||||||
f.enum_test(example.Foo.LUDICROUS)
|
f.enum_test(example.Foo.LUDICROUS)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,38 +6,37 @@ import example
|
||||||
|
|
||||||
t = example.Test()
|
t = example.Test()
|
||||||
try:
|
try:
|
||||||
t.unknown()
|
t.unknown()
|
||||||
except RuntimeError,e:
|
except RuntimeError, e:
|
||||||
print "incomplete type", e.args[0]
|
print "incomplete type", e.args[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t.simple()
|
t.simple()
|
||||||
except RuntimeError,e:
|
except RuntimeError, e:
|
||||||
print e.args[0]
|
print e.args[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t.message()
|
t.message()
|
||||||
except RuntimeError,e:
|
except RuntimeError, e:
|
||||||
print e.args[0]
|
print e.args[0]
|
||||||
|
|
||||||
if not example.is_python_builtin():
|
if not example.is_python_builtin():
|
||||||
try:
|
try:
|
||||||
t.hosed()
|
t.hosed()
|
||||||
except example.Exc,e:
|
except example.Exc, e:
|
||||||
print e.code, e.msg
|
print e.code, e.msg
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
t.hosed()
|
t.hosed()
|
||||||
except BaseException,e:
|
except BaseException, e:
|
||||||
# Throwing builtin classes as exceptions not supported (-builtin option)
|
# Throwing builtin classes as exceptions not supported (-builtin
|
||||||
|
# option)
|
||||||
print e
|
print e
|
||||||
|
|
||||||
for i in range(1,4):
|
for i in range(1, 4):
|
||||||
try:
|
try:
|
||||||
t.multi(i)
|
t.multi(i)
|
||||||
except RuntimeError,e:
|
except RuntimeError, e:
|
||||||
print e.args[0]
|
print e.args[0]
|
||||||
except example.Exc,e:
|
except example.Exc, e:
|
||||||
print e.code, e.msg
|
print e.code, e.msg
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
import example
|
import example
|
||||||
|
|
||||||
if example.is_python_builtin():
|
if example.is_python_builtin():
|
||||||
print "Skipping example: -builtin option does not support %exceptionclass"
|
print "Skipping example: -builtin option does not support %exceptionclass"
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
q = example.intQueue(10)
|
q = example.intQueue(10)
|
||||||
|
|
||||||
|
|
@ -12,18 +12,18 @@ print "Inserting items into intQueue"
|
||||||
print type(example.FullError)
|
print type(example.FullError)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for i in range(0,100):
|
for i in range(0, 100):
|
||||||
q.enqueue(i)
|
q.enqueue(i)
|
||||||
except example.FullError,e:
|
except example.FullError, e:
|
||||||
print "Maxsize is", e.maxsize
|
print "Maxsize is", e.maxsize
|
||||||
|
|
||||||
print "Removing items"
|
print "Removing items"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
q.dequeue()
|
q.dequeue()
|
||||||
except example.EmptyError,e:
|
except example.EmptyError, e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
q = example.doubleQueue(1000)
|
q = example.doubleQueue(1000)
|
||||||
|
|
@ -31,21 +31,15 @@ q = example.doubleQueue(1000)
|
||||||
print "Inserting items into doubleQueue"
|
print "Inserting items into doubleQueue"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for i in range(0,10000):
|
for i in range(0, 10000):
|
||||||
q.enqueue(i*1.5)
|
q.enqueue(i * 1.5)
|
||||||
except example.FullError,e:
|
except example.FullError, e:
|
||||||
print "Maxsize is", e.maxsize
|
print "Maxsize is", e.maxsize
|
||||||
|
|
||||||
print "Removing items"
|
print "Removing items"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
q.dequeue()
|
q.dequeue()
|
||||||
except example.EmptyError,e:
|
except example.EmptyError, e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,18 @@
|
||||||
|
|
||||||
# This file illustrates the cross language polymorphism using directors.
|
# This file illustrates the cross language polymorphism using directors.
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
|
|
||||||
# CEO class, which overrides Employee::getPosition().
|
# CEO class, which overrides Employee::getPosition().
|
||||||
|
|
||||||
class CEO(example.Manager):
|
class CEO(example.Manager):
|
||||||
def __init__(self, name):
|
|
||||||
example.Manager.__init__(self, name)
|
def __init__(self, name):
|
||||||
def getPosition(self):
|
example.Manager.__init__(self, name)
|
||||||
return "CEO"
|
|
||||||
|
def getPosition(self):
|
||||||
|
return "CEO"
|
||||||
|
|
||||||
|
|
||||||
# Create an instance of our employee extension class, CEO. The calls to
|
# Create an instance of our employee extension class, CEO. The calls to
|
||||||
|
|
@ -78,4 +80,3 @@ print "----------------------"
|
||||||
# All done.
|
# All done.
|
||||||
|
|
||||||
print "python exit"
|
print "python exit"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
a = 37
|
a = 37
|
||||||
b = 42
|
b = 42
|
||||||
|
|
@ -10,9 +10,9 @@ b = 42
|
||||||
print "Trying some C callback functions"
|
print "Trying some C callback functions"
|
||||||
print " a =", a
|
print " a =", a
|
||||||
print " b =", b
|
print " b =", b
|
||||||
print " ADD(a,b) =", example.do_op(a,b,example.ADD)
|
print " ADD(a,b) =", example.do_op(a, b, example.ADD)
|
||||||
print " SUB(a,b) =", example.do_op(a,b,example.SUB)
|
print " SUB(a,b) =", example.do_op(a, b, example.SUB)
|
||||||
print " MUL(a,b) =", example.do_op(a,b,example.MUL)
|
print " MUL(a,b) =", example.do_op(a, b, example.MUL)
|
||||||
|
|
||||||
print "Here is what the C callback function objects look like in Python"
|
print "Here is what the C callback function objects look like in Python"
|
||||||
print " ADD =", example.ADD
|
print " ADD =", example.ADD
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
a = 37
|
a = 37
|
||||||
b = 42
|
b = 42
|
||||||
|
|
@ -10,9 +10,9 @@ b = 42
|
||||||
print "Trying some C callback functions"
|
print "Trying some C callback functions"
|
||||||
print " a =", a
|
print " a =", a
|
||||||
print " b =", b
|
print " b =", b
|
||||||
print " ADD(a,b) =", example.do_op(a,b,example.ADD)
|
print " ADD(a,b) =", example.do_op(a, b, example.ADD)
|
||||||
print " SUB(a,b) =", example.do_op(a,b,example.SUB)
|
print " SUB(a,b) =", example.do_op(a, b, example.SUB)
|
||||||
print " MUL(a,b) =", example.do_op(a,b,example.MUL)
|
print " MUL(a,b) =", example.do_op(a, b, example.MUL)
|
||||||
|
|
||||||
print "Here is what the C callback function objects look like in Python"
|
print "Here is what the C callback function objects look like in Python"
|
||||||
print " ADD =", example.ADD
|
print " ADD =", example.ADD
|
||||||
|
|
@ -20,5 +20,5 @@ print " SUB =", example.SUB
|
||||||
print " MUL =", example.MUL
|
print " MUL =", example.MUL
|
||||||
|
|
||||||
print "Call the functions directly..."
|
print "Call the functions directly..."
|
||||||
print " add(a,b) =", example.add(a,b)
|
print " add(a,b) =", example.add(a, b)
|
||||||
print " sub(a,b) =", example.sub(a,b)
|
print " sub(a,b) =", example.sub(a, b)
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,9 @@ b = example.doubleSum(100.0)
|
||||||
# Use the objects. They should be callable just like a normal
|
# Use the objects. They should be callable just like a normal
|
||||||
# python function.
|
# python function.
|
||||||
|
|
||||||
for i in range(0,100):
|
for i in range(0, 100):
|
||||||
a(i) # Note: function call
|
a(i) # Note: function call
|
||||||
b(math.sqrt(i)) # Note: function call
|
b(math.sqrt(i)) # Note: function call
|
||||||
|
|
||||||
print a.result()
|
print a.result()
|
||||||
print b.result()
|
print b.result()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,31 +81,27 @@ x = d.toBase()
|
||||||
print " Spam -> Base -> Foo : ",
|
print " Spam -> Base -> Foo : ",
|
||||||
y = foo.Foo_fromBase(x)
|
y = foo.Foo_fromBase(x)
|
||||||
if y:
|
if y:
|
||||||
print "bad swig"
|
print "bad swig"
|
||||||
else:
|
else:
|
||||||
print "good swig"
|
print "good swig"
|
||||||
|
|
||||||
print " Spam -> Base -> Bar : ",
|
print " Spam -> Base -> Bar : ",
|
||||||
y = bar.Bar_fromBase(x)
|
y = bar.Bar_fromBase(x)
|
||||||
if y:
|
if y:
|
||||||
print "good swig"
|
print "good swig"
|
||||||
else:
|
else:
|
||||||
print "bad swig"
|
print "bad swig"
|
||||||
|
|
||||||
print " Spam -> Base -> Spam : ",
|
print " Spam -> Base -> Spam : ",
|
||||||
y = spam.Spam_fromBase(x)
|
y = spam.Spam_fromBase(x)
|
||||||
if y:
|
if y:
|
||||||
print "good swig"
|
print "good swig"
|
||||||
else:
|
else:
|
||||||
print "bad swig"
|
print "bad swig"
|
||||||
|
|
||||||
print " Foo -> Spam : ",
|
print " Foo -> Spam : ",
|
||||||
y = spam.Spam_fromBase(b)
|
y = spam.Spam_fromBase(b)
|
||||||
if y:
|
if y:
|
||||||
print "bad swig"
|
print "bad swig"
|
||||||
else:
|
else:
|
||||||
print "good swig"
|
print "good swig"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import os.path
|
||||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3, 0):
|
||||||
import py2.pkg2
|
import py2.pkg2
|
||||||
print " Finished importing py2.pkg2"
|
print " Finished importing py2.pkg2"
|
||||||
else:
|
else:
|
||||||
import py3.pkg2
|
import py3.pkg2
|
||||||
print " Finished importing py3.pkg2"
|
print " Finished importing py3.pkg2"
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import os.path
|
||||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3, 0):
|
||||||
import py2.pkg2
|
import py2.pkg2
|
||||||
print " Finished importing py2.pkg2"
|
print " Finished importing py2.pkg2"
|
||||||
else:
|
else:
|
||||||
import py3.pkg2
|
import py3.pkg2
|
||||||
print " Finished importing py3.pkg2"
|
print " Finished importing py3.pkg2"
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import os.path
|
||||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3, 0):
|
||||||
import py2.pkg2
|
import py2.pkg2
|
||||||
print " Finished importing py2.pkg2"
|
print " Finished importing py2.pkg2"
|
||||||
else:
|
else:
|
||||||
import py3.pkg2
|
import py3.pkg2
|
||||||
print " Finished importing py3.pkg2"
|
print " Finished importing py3.pkg2"
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import os.path
|
||||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||||
print "Testing " + testname + " - %module(package=...) with -relativeimport"
|
print "Testing " + testname + " - %module(package=...) with -relativeimport"
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3, 0):
|
||||||
import py2.pkg2.bar
|
import py2.pkg2.bar
|
||||||
print " Finished importing py2.pkg2.bar"
|
print " Finished importing py2.pkg2.bar"
|
||||||
else:
|
else:
|
||||||
import py3.pkg2.bar
|
import py3.pkg2.bar
|
||||||
print " Finished importing py3.pkg2.bar"
|
print " Finished importing py3.pkg2.bar"
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import os.path
|
||||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3, 0):
|
||||||
import py2.pkg2.bar
|
import py2.pkg2.bar
|
||||||
print " Finished importing py2.pkg2.bar"
|
print " Finished importing py2.pkg2.bar"
|
||||||
else:
|
else:
|
||||||
import py3.pkg2.bar
|
import py3.pkg2.bar
|
||||||
print " Finished importing py3.pkg2.bar"
|
print " Finished importing py3.pkg2.bar"
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import os.path
|
||||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||||
print "Testing " + testname + " - %module(package=...) with -relativeimport"
|
print "Testing " + testname + " - %module(package=...) with -relativeimport"
|
||||||
|
|
||||||
if sys.version_info < (3,0):
|
if sys.version_info < (3, 0):
|
||||||
import py2.pkg2.bar
|
import py2.pkg2.bar
|
||||||
print " Finished importing py2.pkg2.bar"
|
print " Finished importing py2.pkg2.bar"
|
||||||
else:
|
else:
|
||||||
import py3.pkg2.bar
|
import py3.pkg2.bar
|
||||||
print " Finished importing py3.pkg2.bar"
|
print " Finished importing py3.pkg2.bar"
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,5 @@ print " Finished importing pkg2.foo"
|
||||||
|
|
||||||
var2 = pkg2.foo.Pkg2_Foo()
|
var2 = pkg2.foo.Pkg2_Foo()
|
||||||
if str(type(var2)).find("'pkg2.foo.Pkg2_Foo'") == -1:
|
if str(type(var2)).find("'pkg2.foo.Pkg2_Foo'") == -1:
|
||||||
raise RuntimeError("failed type checking: " + str(type(var2)))
|
raise RuntimeError("failed type checking: " + str(type(var2)))
|
||||||
print " Successfully created object pkg2.foo.Pkg2_Foo"
|
print " Successfully created object pkg2.foo.Pkg2_Foo"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ print "Testing " + testname + " - %module(package=...) + python 'import' in __in
|
||||||
import pkg1.pkg2.foo
|
import pkg1.pkg2.foo
|
||||||
print " Finished importing pkg1.pkg2.foo"
|
print " Finished importing pkg1.pkg2.foo"
|
||||||
|
|
||||||
var2 = pkg1.pkg2.foo.Pkg2_Foo();
|
var2 = pkg1.pkg2.foo.Pkg2_Foo()
|
||||||
if str(type(var2)).find("'pkg1.pkg2.foo.Pkg2_Foo'") == -1:
|
if str(type(var2)).find("'pkg1.pkg2.foo.Pkg2_Foo'") == -1:
|
||||||
raise RuntimeError("failed type checking: " + str(type(var2)))
|
raise RuntimeError("failed type checking: " + str(type(var2)))
|
||||||
print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo"
|
print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo"
|
||||||
|
|
|
||||||
|
|
@ -81,31 +81,27 @@ x = d.toBase()
|
||||||
print " Spam -> Base -> Foo : ",
|
print " Spam -> Base -> Foo : ",
|
||||||
y = foo.intFoo_fromBase(x)
|
y = foo.intFoo_fromBase(x)
|
||||||
if y:
|
if y:
|
||||||
print "bad swig"
|
print "bad swig"
|
||||||
else:
|
else:
|
||||||
print "good swig"
|
print "good swig"
|
||||||
|
|
||||||
print " Spam -> Base -> Bar : ",
|
print " Spam -> Base -> Bar : ",
|
||||||
y = bar.intBar_fromBase(x)
|
y = bar.intBar_fromBase(x)
|
||||||
if y:
|
if y:
|
||||||
print "good swig"
|
print "good swig"
|
||||||
else:
|
else:
|
||||||
print "bad swig"
|
print "bad swig"
|
||||||
|
|
||||||
print " Spam -> Base -> Spam : ",
|
print " Spam -> Base -> Spam : ",
|
||||||
y = spam.intSpam_fromBase(x)
|
y = spam.intSpam_fromBase(x)
|
||||||
if y:
|
if y:
|
||||||
print "good swig"
|
print "good swig"
|
||||||
else:
|
else:
|
||||||
print "bad swig"
|
print "bad swig"
|
||||||
|
|
||||||
print " Foo -> Spam : ",
|
print " Foo -> Spam : ",
|
||||||
y = spam.intSpam_fromBase(b)
|
y = spam.intSpam_fromBase(b)
|
||||||
if y:
|
if y:
|
||||||
print "bad swig"
|
print "bad swig"
|
||||||
else:
|
else:
|
||||||
print "good swig"
|
print "good swig"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ JvAttachCurrentThread(None, None)
|
||||||
e1 = Example(1)
|
e1 = Example(1)
|
||||||
e2 = Example(2)
|
e2 = Example(2)
|
||||||
|
|
||||||
print e1.Add(1,2)
|
print e1.Add(1, 2)
|
||||||
print e1.Add(1.0,2.0)
|
print e1.Add(1.0, 2.0)
|
||||||
e3 = e1.Add(e1,e2)
|
e3 = e1.Add(e1, e2)
|
||||||
print e3.mPublicInt
|
print e3.mPublicInt
|
||||||
|
|
||||||
print e1.Add("1","2")
|
print e1.Add("1", "2")
|
||||||
|
|
||||||
JvDetachCurrentThread()
|
JvDetachCurrentThread()
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
# Call our gcd() function
|
# Call our gcd() function
|
||||||
|
|
||||||
x = 42
|
x = 42
|
||||||
y = 105
|
y = 105
|
||||||
g = example.gcd(x,y)
|
g = example.gcd(x, y)
|
||||||
print "The gcd of %d and %d is %d" % (x,y,g)
|
print "The gcd of %d and %d is %d" % (x, y, g)
|
||||||
|
|
||||||
# Call the gcdmain() function
|
# Call the gcdmain() function
|
||||||
example.gcdmain(["gcdmain","42","105"])
|
example.gcdmain(["gcdmain", "42", "105"])
|
||||||
|
|
||||||
# Call the count function
|
# Call the count function
|
||||||
print example.count("Hello World", "l")
|
print example.count("Hello World", "l")
|
||||||
|
|
@ -18,10 +18,3 @@ print example.count("Hello World", "l")
|
||||||
# Call the capitalize function
|
# Call the capitalize function
|
||||||
|
|
||||||
print example.capitalize("hello world")
|
print example.capitalize("hello world")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,20 @@
|
||||||
# Operator overloading example
|
# Operator overloading example
|
||||||
import example
|
import example
|
||||||
|
|
||||||
a = example.Complex(2,3)
|
a = example.Complex(2, 3)
|
||||||
b = example.Complex(-5,10)
|
b = example.Complex(-5, 10)
|
||||||
|
|
||||||
print "a =",a
|
print "a =", a
|
||||||
print "b =",b
|
print "b =", b
|
||||||
|
|
||||||
c = a + b
|
c = a + b
|
||||||
print "c =",c
|
print "c =", c
|
||||||
print "a*b =",a*b
|
print "a*b =", a * b
|
||||||
print "a-c =",a-c
|
print "a-c =", a - c
|
||||||
|
|
||||||
e = example.ComplexCopy(a-c)
|
e = example.ComplexCopy(a - c)
|
||||||
print "e =",e
|
print "e =", e
|
||||||
|
|
||||||
# Big expression
|
# Big expression
|
||||||
f = ((a+b)*(c+b*e)) + (-a)
|
f = ((a + b) * (c + b * e)) + (-a)
|
||||||
print "f =",f
|
print "f =", f
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@ import sys
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
import harness
|
import harness
|
||||||
|
|
||||||
def proc (mod) :
|
|
||||||
for i in range(1000000) :
|
def proc(mod):
|
||||||
|
for i in range(1000000):
|
||||||
x = mod.MyClass()
|
x = mod.MyClass()
|
||||||
|
|
||||||
harness.run(proc)
|
harness.run(proc)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ import sys
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
import harness
|
import harness
|
||||||
|
|
||||||
def proc (mod) :
|
|
||||||
|
def proc(mod):
|
||||||
x = mod.MyClass()
|
x = mod.MyClass()
|
||||||
for i in range(10000000) :
|
for i in range(10000000):
|
||||||
x.func()
|
x.func()
|
||||||
|
|
||||||
harness.run(proc)
|
harness.run(proc)
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ import time
|
||||||
import imp
|
import imp
|
||||||
from subprocess import *
|
from subprocess import *
|
||||||
|
|
||||||
def run (proc) :
|
|
||||||
|
|
||||||
try :
|
def run(proc):
|
||||||
|
|
||||||
|
try:
|
||||||
mod = imp.find_module(sys.argv[1])
|
mod = imp.find_module(sys.argv[1])
|
||||||
mod = imp.load_module(sys.argv[1], *mod)
|
mod = imp.load_module(sys.argv[1], *mod)
|
||||||
|
|
||||||
|
|
@ -14,15 +15,18 @@ def run (proc) :
|
||||||
t2 = time.clock()
|
t2 = time.clock()
|
||||||
print "%s took %f seconds" % (mod.__name__, t2 - t1)
|
print "%s took %f seconds" % (mod.__name__, t2 - t1)
|
||||||
|
|
||||||
except IndexError :
|
except IndexError:
|
||||||
proc = Popen([sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE)
|
proc = Popen(
|
||||||
|
[sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE)
|
||||||
(stdout, stderr) = proc.communicate()
|
(stdout, stderr) = proc.communicate()
|
||||||
print stdout
|
print stdout
|
||||||
|
|
||||||
proc = Popen([sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE)
|
proc = Popen(
|
||||||
|
[sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE)
|
||||||
(stdout, stderr) = proc.communicate()
|
(stdout, stderr) = proc.communicate()
|
||||||
print stdout
|
print stdout
|
||||||
|
|
||||||
proc = Popen([sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE)
|
proc = Popen(
|
||||||
|
[sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE)
|
||||||
(stdout, stderr) = proc.communicate()
|
(stdout, stderr) = proc.communicate()
|
||||||
print stdout
|
print stdout
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ import sys
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
import harness
|
import harness
|
||||||
|
|
||||||
def proc (mod) :
|
|
||||||
|
def proc(mod):
|
||||||
x = mod.H()
|
x = mod.H()
|
||||||
for i in range(10000000) :
|
for i in range(10000000):
|
||||||
x.func()
|
x.func()
|
||||||
|
|
||||||
harness.run(proc)
|
harness.run(proc)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ import sys
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
import harness
|
import harness
|
||||||
|
|
||||||
def proc (mod) :
|
|
||||||
|
def proc(mod):
|
||||||
x = mod.H()
|
x = mod.H()
|
||||||
for i in range(10000000) :
|
for i in range(10000000):
|
||||||
x += i
|
x += i
|
||||||
|
|
||||||
harness.run(proc)
|
harness.run(proc)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ import sys
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
import harness
|
import harness
|
||||||
|
|
||||||
def proc (mod) :
|
|
||||||
|
def proc(mod):
|
||||||
x = mod.MyClass()
|
x = mod.MyClass()
|
||||||
for i in range(10000000) :
|
for i in range(10000000):
|
||||||
x = x + i
|
x = x + i
|
||||||
|
|
||||||
harness.run(proc)
|
harness.run(proc)
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import example;
|
import example
|
||||||
|
|
||||||
# First create some objects using the pointer library.
|
# First create some objects using the pointer library.
|
||||||
print "Testing the pointer library";
|
print "Testing the pointer library"
|
||||||
a = example.new_intp();
|
a = example.new_intp()
|
||||||
b = example.new_intp();
|
b = example.new_intp()
|
||||||
c = example.new_intp();
|
c = example.new_intp()
|
||||||
example.intp_assign(a,37);
|
example.intp_assign(a, 37)
|
||||||
example.intp_assign(b,42);
|
example.intp_assign(b, 42)
|
||||||
|
|
||||||
print " a =",a
|
print " a =", a
|
||||||
print " b =",b
|
print " b =", b
|
||||||
print " c =",c
|
print " c =", c
|
||||||
|
|
||||||
# Call the add() function with some pointers
|
# Call the add() function with some pointers
|
||||||
example.add(a,b,c)
|
example.add(a, b, c)
|
||||||
|
|
||||||
# Now get the result
|
# Now get the result
|
||||||
r = example.intp_value(c)
|
r = example.intp_value(c)
|
||||||
print " 37 + 42 =",r
|
print " 37 + 42 =", r
|
||||||
|
|
||||||
# Clean up the pointers
|
# Clean up the pointers
|
||||||
example.delete_intp(a)
|
example.delete_intp(a)
|
||||||
|
|
@ -30,15 +30,12 @@ example.delete_intp(c)
|
||||||
# This should be much easier. Now how it is no longer
|
# This should be much easier. Now how it is no longer
|
||||||
# necessary to manufacture pointers.
|
# necessary to manufacture pointers.
|
||||||
|
|
||||||
print "Trying the typemap library";
|
print "Trying the typemap library"
|
||||||
r = example.sub(37,42)
|
r = example.sub(37, 42)
|
||||||
print " 37 - 42 =",r
|
print " 37 - 42 =", r
|
||||||
|
|
||||||
# Now try the version with multiple return values
|
# Now try the version with multiple return values
|
||||||
|
|
||||||
print "Testing multiple return values";
|
print "Testing multiple return values"
|
||||||
q,r = example.divide(42,37)
|
q, r = example.divide(42, 37)
|
||||||
print " 42/37 = %d remainder %d" % (q,r)
|
print " 42/37 = %d remainder %d" % (q, r)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,22 +7,22 @@ import example
|
||||||
# ----- Object creation -----
|
# ----- Object creation -----
|
||||||
|
|
||||||
print "Creating some objects:"
|
print "Creating some objects:"
|
||||||
a = example.Vector(3,4,5)
|
a = example.Vector(3, 4, 5)
|
||||||
b = example.Vector(10,11,12)
|
b = example.Vector(10, 11, 12)
|
||||||
|
|
||||||
print " Created",a.cprint()
|
print " Created", a.cprint()
|
||||||
print " Created",b.cprint()
|
print " Created", b.cprint()
|
||||||
|
|
||||||
# ----- Call an overloaded operator -----
|
# ----- Call an overloaded operator -----
|
||||||
|
|
||||||
# This calls the wrapper we placed around
|
# This calls the wrapper we placed around
|
||||||
#
|
#
|
||||||
# operator+(const Vector &a, const Vector &)
|
# operator+(const Vector &a, const Vector &)
|
||||||
#
|
#
|
||||||
# It returns a new allocated object.
|
# It returns a new allocated object.
|
||||||
|
|
||||||
print "Adding a+b"
|
print "Adding a+b"
|
||||||
c = example.addv(a,b)
|
c = example.addv(a, b)
|
||||||
print " a+b =", c.cprint()
|
print " a+b =", c.cprint()
|
||||||
|
|
||||||
# Note: Unless we free the result, a memory leak will occur
|
# Note: Unless we free the result, a memory leak will occur
|
||||||
|
|
@ -33,25 +33,25 @@ del c
|
||||||
# Note: Using the high-level interface here
|
# Note: Using the high-level interface here
|
||||||
print "Creating an array of vectors"
|
print "Creating an array of vectors"
|
||||||
va = example.VectorArray(10)
|
va = example.VectorArray(10)
|
||||||
print " va = ",va
|
print " va = ", va
|
||||||
|
|
||||||
# ----- Set some values in the array -----
|
# ----- Set some values in the array -----
|
||||||
|
|
||||||
# These operators copy the value of $a and $b to the vector array
|
# These operators copy the value of $a and $b to the vector array
|
||||||
va.set(0,a)
|
va.set(0, a)
|
||||||
va.set(1,b)
|
va.set(1, b)
|
||||||
|
|
||||||
va.set(2,example.addv(a,b))
|
va.set(2, example.addv(a, b))
|
||||||
|
|
||||||
# Get some values from the array
|
# Get some values from the array
|
||||||
|
|
||||||
print "Getting some array values"
|
print "Getting some array values"
|
||||||
for i in range(0,5):
|
for i in range(0, 5):
|
||||||
print " va(%d) = %s" % (i, va.get(i).cprint())
|
print " va(%d) = %s" % (i, va.get(i).cprint())
|
||||||
|
|
||||||
# Watch under resource meter to check on this
|
# Watch under resource meter to check on this
|
||||||
print "Making sure we don't leak memory."
|
print "Making sure we don't leak memory."
|
||||||
for i in xrange(0,1000000):
|
for i in xrange(0, 1000000):
|
||||||
c = va.get(i % 10)
|
c = va.get(i % 10)
|
||||||
|
|
||||||
# ----- Clean up -----
|
# ----- Clean up -----
|
||||||
|
|
@ -60,4 +60,3 @@ print "Cleaning up"
|
||||||
del va
|
del va
|
||||||
del a
|
del a
|
||||||
del b
|
del b
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
# Call our gcd() function
|
# Call our gcd() function
|
||||||
|
|
||||||
x = 42
|
x = 42
|
||||||
y = 105
|
y = 105
|
||||||
g = example.gcd(x,y)
|
g = example.gcd(x, y)
|
||||||
print "The gcd of %d and %d is %d" % (x,y,g)
|
print "The gcd of %d and %d is %d" % (x, y, g)
|
||||||
|
|
||||||
# Manipulate the Foo global variable
|
# Manipulate the Foo global variable
|
||||||
|
|
||||||
|
|
@ -19,12 +19,3 @@ example.cvar.Foo = 3.1415926
|
||||||
|
|
||||||
# See if the change took effect
|
# See if the change took effect
|
||||||
print "Foo = ", example.cvar.Foo
|
print "Foo = ", example.cvar.Foo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# This file illustrates the proxy class C++ interface generated
|
# This file illustrates the proxy class C++ interface generated
|
||||||
# by SWIG.
|
# by SWIG.
|
||||||
|
|
||||||
import example
|
import example
|
||||||
|
|
||||||
# ----- Object creation -----
|
# ----- Object creation -----
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ print " Created square", s
|
||||||
|
|
||||||
# ----- Access a static member -----
|
# ----- Access a static member -----
|
||||||
|
|
||||||
print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
|
print "\nA total of", example.cvar.Shape_nshapes, "shapes were created"
|
||||||
|
|
||||||
# ----- Member data access -----
|
# ----- Member data access -----
|
||||||
|
|
||||||
|
|
@ -30,16 +30,16 @@ s.x = -10
|
||||||
s.y = 5
|
s.y = 5
|
||||||
|
|
||||||
print "\nHere is their current position:"
|
print "\nHere is their current position:"
|
||||||
print " Circle = (%f, %f)" % (c.x,c.y)
|
print " Circle = (%f, %f)" % (c.x, c.y)
|
||||||
print " Square = (%f, %f)" % (s.x,s.y)
|
print " Square = (%f, %f)" % (s.x, s.y)
|
||||||
|
|
||||||
# ----- Call some methods -----
|
# ----- Call some methods -----
|
||||||
|
|
||||||
print "\nHere are some properties of the shapes:"
|
print "\nHere are some properties of the shapes:"
|
||||||
for o in [c,s]:
|
for o in [c, s]:
|
||||||
print " ", o
|
print " ", o
|
||||||
print " area = ", o.area()
|
print " area = ", o.area()
|
||||||
print " perimeter = ", o.perimeter()
|
print " perimeter = ", o.perimeter()
|
||||||
|
|
||||||
print "\nGuess I'll clean up now"
|
print "\nGuess I'll clean up now"
|
||||||
|
|
||||||
|
|
@ -50,6 +50,5 @@ del cc
|
||||||
del ss
|
del ss
|
||||||
|
|
||||||
s = 3
|
s = 3
|
||||||
print example.cvar.Shape_nshapes,"shapes remain"
|
print example.cvar.Shape_nshapes, "shapes remain"
|
||||||
print "Goodbye"
|
print "Goodbye"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ pmap["hi"] = 1
|
||||||
pmap["hello"] = 2
|
pmap["hello"] = 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dmap = {}
|
dmap = {}
|
||||||
dmap["hello"] = 1.0
|
dmap["hello"] = 1.0
|
||||||
dmap["hi"] = 2.0
|
dmap["hi"] = 2.0
|
||||||
|
|
@ -28,8 +26,8 @@ for i in dmap.iterkeys():
|
||||||
for i in dmap.itervalues():
|
for i in dmap.itervalues():
|
||||||
print "val", i
|
print "val", i
|
||||||
|
|
||||||
for k,v in dmap.iteritems():
|
for k, v in dmap.iteritems():
|
||||||
print "item", k,v
|
print "item", k, v
|
||||||
|
|
||||||
dmap = example.DoubleMap()
|
dmap = example.DoubleMap()
|
||||||
dmap["hello"] = 1.0
|
dmap["hello"] = 1.0
|
||||||
|
|
@ -41,8 +39,8 @@ for i in dmap.iterkeys():
|
||||||
for i in dmap.itervalues():
|
for i in dmap.itervalues():
|
||||||
print "val", i
|
print "val", i
|
||||||
|
|
||||||
for k,v in dmap.iteritems():
|
for k, v in dmap.iteritems():
|
||||||
print "item", k,v
|
print "item", k, v
|
||||||
|
|
||||||
|
|
||||||
print dmap.items()
|
print dmap.items()
|
||||||
|
|
@ -54,7 +52,6 @@ print hmap.keys()
|
||||||
print hmap.values()
|
print hmap.values()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dmap = {}
|
dmap = {}
|
||||||
dmap["hello"] = 2
|
dmap["hello"] = 2
|
||||||
dmap["hi"] = 4
|
dmap["hi"] = 4
|
||||||
|
|
@ -76,7 +73,7 @@ for i in dmap.itervalues():
|
||||||
for i in dmap.iteritems():
|
for i in dmap.iteritems():
|
||||||
print "item", i
|
print "item", i
|
||||||
|
|
||||||
for k,v in dmap.iteritems():
|
for k, v in dmap.iteritems():
|
||||||
print "item", k,v
|
print "item", k, v
|
||||||
|
|
||||||
print dmap
|
print dmap
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ import example
|
||||||
|
|
||||||
# Call average with a Python list...
|
# Call average with a Python list...
|
||||||
|
|
||||||
print example.average([1,2,3,4])
|
print example.average([1, 2, 3, 4])
|
||||||
|
|
||||||
# ... or a wrapped std::vector<int>
|
# ... or a wrapped std::vector<int>
|
||||||
|
|
||||||
v = example.IntVector(4)
|
v = example.IntVector(4)
|
||||||
for i in range(len(v)):
|
for i in range(len(v)):
|
||||||
v[i] = i+1
|
v[i] = i + 1
|
||||||
print example.average(v)
|
print example.average(v)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,8 +22,8 @@ print example.half((1.0, 1.5, 2.0, 2.5, 3.0))
|
||||||
# ... or a wrapped std::vector<double>
|
# ... or a wrapped std::vector<double>
|
||||||
|
|
||||||
v = example.DoubleVector()
|
v = example.DoubleVector()
|
||||||
for i in [1,2,3,4]:
|
for i in [1, 2, 3, 4]:
|
||||||
v.append(i)
|
v.append(i)
|
||||||
print example.half(v)
|
print example.half(v)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,6 +31,5 @@ print example.half(v)
|
||||||
|
|
||||||
example.halve_in_place(v)
|
example.halve_in_place(v)
|
||||||
for i in range(len(v)):
|
for i in range(len(v)):
|
||||||
print v[i], "; ",
|
print v[i], "; ",
|
||||||
print
|
print
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,32 +3,30 @@
|
||||||
import example
|
import example
|
||||||
|
|
||||||
# Call some templated functions
|
# Call some templated functions
|
||||||
print example.maxint(3,7)
|
print example.maxint(3, 7)
|
||||||
print example.maxdouble(3.14,2.18)
|
print example.maxdouble(3.14, 2.18)
|
||||||
|
|
||||||
# Create some class
|
# Create some class
|
||||||
|
|
||||||
iv = example.vecint(100)
|
iv = example.vecint(100)
|
||||||
dv = example.vecdouble(1000)
|
dv = example.vecdouble(1000)
|
||||||
|
|
||||||
for i in range(0,100):
|
for i in range(0, 100):
|
||||||
iv.setitem(i,2*i)
|
iv.setitem(i, 2 * i)
|
||||||
|
|
||||||
for i in range(0,1000):
|
for i in range(0, 1000):
|
||||||
dv.setitem(i, 1.0/(i+1))
|
dv.setitem(i, 1.0 / (i + 1))
|
||||||
|
|
||||||
sum = 0
|
sum = 0
|
||||||
for i in range(0,100):
|
for i in range(0, 100):
|
||||||
sum = sum + iv.getitem(i)
|
sum = sum + iv.getitem(i)
|
||||||
|
|
||||||
print sum
|
print sum
|
||||||
|
|
||||||
sum = 0.0
|
sum = 0.0
|
||||||
for i in range(0,1000):
|
for i in range(0, 1000):
|
||||||
sum = sum + dv.getitem(i)
|
sum = sum + dv.getitem(i)
|
||||||
print sum
|
print sum
|
||||||
|
|
||||||
del iv
|
del iv
|
||||||
del dv
|
del dv
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
# file: runme.py
|
# file: runme.py
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import example
|
import example
|
||||||
|
|
||||||
# Call printf
|
# Call printf
|
||||||
example.printf("Hello World. I'm printf\n")
|
example.printf("Hello World. I'm printf\n")
|
||||||
|
|
||||||
# Note: We call printf, but use *python* string formatting
|
# Note: We call printf, but use *python* string formatting
|
||||||
for i in range(0,10):
|
for i in range(0, 10):
|
||||||
example.printf("i is %d\n" % i)
|
example.printf("i is %d\n" % i)
|
||||||
|
|
||||||
# This will probably be garbled because %d is interpreted by C
|
# This will probably be garbled because %d is interpreted by C
|
||||||
|
|
@ -15,21 +15,13 @@ example.printf("The value is %d\n")
|
||||||
|
|
||||||
stdout = example.stdout_stream()
|
stdout = example.stdout_stream()
|
||||||
# Call fprintf
|
# Call fprintf
|
||||||
example.fprintf(stdout,"Hello World. I'm fprintf\n")
|
example.fprintf(stdout, "Hello World. I'm fprintf\n")
|
||||||
for i in range(0,10):
|
for i in range(0, 10):
|
||||||
example.fprintf(stdout,"i is %d\n" % i)
|
example.fprintf(stdout, "i is %d\n" % i)
|
||||||
|
|
||||||
# This won't be garbled since %d is not interpreted
|
# This won't be garbled since %d is not interpreted
|
||||||
example.fprintf(stdout,"The value is %d\n")
|
example.fprintf(stdout, "The value is %d\n")
|
||||||
|
|
||||||
# This function calls our NULL-terminated function
|
# This function calls our NULL-terminated function
|
||||||
|
|
||||||
example.printv("Hello","World","this","is","a","test.")
|
example.printv("Hello", "World", "this", "is", "a", "test.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,21 @@ import example
|
||||||
|
|
||||||
# Try to set the values of some global variables
|
# Try to set the values of some global variables
|
||||||
|
|
||||||
example.cvar.ivar = 42
|
example.cvar.ivar = 42
|
||||||
example.cvar.svar = -31000
|
example.cvar.svar = -31000
|
||||||
example.cvar.lvar = 65537
|
example.cvar.lvar = 65537
|
||||||
example.cvar.uivar = 123456
|
example.cvar.uivar = 123456
|
||||||
example.cvar.usvar = 61000
|
example.cvar.usvar = 61000
|
||||||
example.cvar.ulvar = 654321
|
example.cvar.ulvar = 654321
|
||||||
example.cvar.scvar = -13
|
example.cvar.scvar = -13
|
||||||
example.cvar.ucvar = 251
|
example.cvar.ucvar = 251
|
||||||
example.cvar.cvar = "S"
|
example.cvar.cvar = "S"
|
||||||
example.cvar.fvar = 3.14159
|
example.cvar.fvar = 3.14159
|
||||||
example.cvar.dvar = 2.1828
|
example.cvar.dvar = 2.1828
|
||||||
example.cvar.strvar = "Hello World"
|
example.cvar.strvar = "Hello World"
|
||||||
example.cvar.iptrvar= example.new_int(37)
|
example.cvar.iptrvar = example.new_int(37)
|
||||||
example.cvar.ptptr = example.new_Point(37,42)
|
example.cvar.ptptr = example.new_Point(37, 42)
|
||||||
example.cvar.name = "Bill"
|
example.cvar.name = "Bill"
|
||||||
|
|
||||||
# Now print out the values of the variables
|
# Now print out the values of the variables
|
||||||
|
|
||||||
|
|
@ -46,16 +46,16 @@ print "\nVariables (values printed from C)"
|
||||||
|
|
||||||
example.print_vars()
|
example.print_vars()
|
||||||
|
|
||||||
print "\nNow I'm going to try and modify some read only variables";
|
print "\nNow I'm going to try and modify some read only variables"
|
||||||
|
|
||||||
print " Tring to set 'path'";
|
print " Tring to set 'path'"
|
||||||
try:
|
try:
|
||||||
example.cvar.path = "Whoa!"
|
example.cvar.path = "Whoa!"
|
||||||
print "Hey, what's going on?!?! This shouldn't work"
|
print "Hey, what's going on?!?! This shouldn't work"
|
||||||
except:
|
except:
|
||||||
print "Good."
|
print "Good."
|
||||||
|
|
||||||
print " Trying to set 'status'";
|
print " Trying to set 'status'"
|
||||||
try:
|
try:
|
||||||
example.cvar.status = 0
|
example.cvar.status = 0
|
||||||
print "Hey, what's going on?!?! This shouldn't work"
|
print "Hey, what's going on?!?! This shouldn't work"
|
||||||
|
|
@ -70,6 +70,3 @@ example.cvar.pt = example.cvar.ptptr
|
||||||
print "The new value is"
|
print "The new value is"
|
||||||
example.pt_print()
|
example.pt_print()
|
||||||
print "You should see the value", example.Point_print(example.cvar.ptptr)
|
print "You should see the value", example.Point_print(example.cvar.ptptr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue