mirror of https://github.com/pybind/pybind11
Browse Source
This renames example files from `exampleN` to `example-description`. Specifically, the following renaming is applied: example1 -> example-methods-and-attributes example2 -> example-python-types example3 -> example-operator-overloading example4 -> example-constants-and-functions example5 -> example-callbacks (*) example6 -> example-sequence-and-iterators example7 -> example-buffers example8 -> example-custom-ref-counting example9 -> example-modules example10 -> example-numpy-vectorize example11 -> example-arg-keywords-and-defaults example12 -> example-virtual-functions example13 -> example-keep-alive example14 -> example-opaque-types example15 -> example-pickling example16 -> example-inheritance example17 -> example-stl-binders example18 -> example-eval example19 -> example-custom-exceptions * the inheritance parts of example5 are moved into example-inheritance (previously example16), and the remainder is left as example-callbacks. This commit also renames the internal variables ("Example1", "Example2", "Example4", etc.) into non-numeric names ("ExampleMandA", "ExamplePythonTypes", "ExampleWithEnum", etc.) to correspond to the file renaming. The order of tests is preserved, but this can easily be changed if there is some more natural ordering by updating the list in examples/CMakeLists.txt.pull/289/head
68 changed files with 517 additions and 517 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python |
||||
from __future__ import print_function |
||||
import sys |
||||
sys.path.append('.') |
||||
|
||||
from example import test_function |
||||
from example import some_constant |
||||
from example import EMyEnumeration |
||||
from example import EFirstEntry |
||||
from example import ExampleWithEnum |
||||
from example import return_bytes |
||||
from example import print_bytes |
||||
|
||||
print(EMyEnumeration) |
||||
print(EMyEnumeration.EFirstEntry) |
||||
print(EMyEnumeration.ESecondEntry) |
||||
print(EFirstEntry) |
||||
|
||||
print(test_function()) |
||||
print(test_function(7)) |
||||
print(test_function(EMyEnumeration.EFirstEntry)) |
||||
print(test_function(EMyEnumeration.ESecondEntry)) |
||||
print("enum->integer = %i" % int(EMyEnumeration.ESecondEntry)) |
||||
print("integer->enum = %s" % str(EMyEnumeration(2))) |
||||
|
||||
print("A constant = " + str(some_constant)) |
||||
|
||||
print(ExampleWithEnum.EMode) |
||||
print(ExampleWithEnum.EMode.EFirstMode) |
||||
print(ExampleWithEnum.EFirstMode) |
||||
ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode) |
||||
|
||||
print("Equality test 1: " + str( |
||||
ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode) == |
||||
ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode))) |
||||
|
||||
print("Inequality test 1: " + str( |
||||
ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode) != |
||||
ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode))) |
||||
|
||||
print("Equality test 2: " + str( |
||||
ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode) == |
||||
ExampleWithEnum.test_function(ExampleWithEnum.ESecondMode))) |
||||
|
||||
print("Inequality test 2: " + str( |
||||
ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode) != |
||||
ExampleWithEnum.test_function(ExampleWithEnum.ESecondMode))) |
||||
|
||||
x = { |
||||
ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode): 1, |
||||
ExampleWithEnum.test_function(ExampleWithEnum.ESecondMode): 2 |
||||
} |
||||
|
||||
x[ExampleWithEnum.test_function(ExampleWithEnum.EFirstMode)] = 3 |
||||
x[ExampleWithEnum.test_function(ExampleWithEnum.ESecondMode)] = 4 |
||||
print("Hashing test = " + str(x)) |
||||
|
||||
print_bytes(return_bytes()) |
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
from example import example_eval |
||||
|
||||
example_eval() |
||||
|
||||
|
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
example/example-inheritance.cpp -- inheritance, automatic upcasting for polymorphic types |
||||
|
||||
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> |
||||
|
||||
All rights reserved. Use of this source code is governed by a |
||||
BSD-style license that can be found in the LICENSE file. |
||||
*/ |
||||
|
||||
#include "example.h" |
||||
|
||||
class Pet { |
||||
public: |
||||
Pet(const std::string &name, const std::string &species) |
||||
: m_name(name), m_species(species) {} |
||||
std::string name() const { return m_name; } |
||||
std::string species() const { return m_species; } |
||||
private: |
||||
std::string m_name; |
||||
std::string m_species; |
||||
}; |
||||
|
||||
class Dog : public Pet { |
||||
public: |
||||
Dog(const std::string &name) : Pet(name, "dog") {} |
||||
void bark() const { std::cout << "Woof!" << std::endl; } |
||||
}; |
||||
|
||||
class Rabbit : public Pet { |
||||
public: |
||||
Rabbit(const std::string &name) : Pet(name, "parrot") {} |
||||
}; |
||||
|
||||
void pet_print(const Pet &pet) { |
||||
std::cout << pet.name() + " is a " + pet.species() << std::endl; |
||||
} |
||||
|
||||
void dog_bark(const Dog &dog) { |
||||
dog.bark(); |
||||
} |
||||
|
||||
|
||||
struct BaseClass { virtual ~BaseClass() {} }; |
||||
struct DerivedClass1 : BaseClass { }; |
||||
struct DerivedClass2 : BaseClass { }; |
||||
|
||||
void init_ex_inheritance(py::module &m) { |
||||
py::class_<Pet> pet_class(m, "Pet"); |
||||
pet_class |
||||
.def(py::init<std::string, std::string>()) |
||||
.def("name", &Pet::name) |
||||
.def("species", &Pet::species); |
||||
|
||||
/* One way of declaring a subclass relationship: reference parent's class_ object */ |
||||
py::class_<Dog>(m, "Dog", pet_class) |
||||
.def(py::init<std::string>()); |
||||
|
||||
/* Another way of declaring a subclass relationship: reference parent's C++ type */ |
||||
py::class_<Rabbit>(m, "Rabbit", py::base<Pet>()) |
||||
.def(py::init<std::string>()); |
||||
|
||||
m.def("pet_print", pet_print); |
||||
m.def("dog_bark", dog_bark); |
||||
|
||||
py::class_<BaseClass>(m, "BaseClass").def(py::init<>()); |
||||
py::class_<DerivedClass1>(m, "DerivedClass1").def(py::init<>()); |
||||
py::class_<DerivedClass2>(m, "DerivedClass2").def(py::init<>()); |
||||
|
||||
m.def("return_class_1", []() -> BaseClass* { return new DerivedClass1(); }); |
||||
m.def("return_class_2", []() -> BaseClass* { return new DerivedClass2(); }); |
||||
m.def("return_none", []() -> BaseClass* { return nullptr; }); |
||||
} |
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
example/example-methods-and-attributes.cpp -- constructors, deconstructors, attribute access, |
||||
__str__, argument and return value conventions |
||||
|
||||
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> |
||||
|
||||
All rights reserved. Use of this source code is governed by a |
||||
BSD-style license that can be found in the LICENSE file. |
||||
*/ |
||||
|
||||
#include "example.h" |
||||
|
||||
class ExampleMandA { |
||||
public: |
||||
ExampleMandA() { |
||||
cout << "Called ExampleMandA default constructor.." << endl; |
||||
} |
||||
ExampleMandA(int value) : value(value) { |
||||
cout << "Called ExampleMandA constructor with value " << value << ".." << endl; |
||||
} |
||||
ExampleMandA(const ExampleMandA &e) : value(e.value) { |
||||
cout << "Called ExampleMandA copy constructor with value " << value << ".." << endl; |
||||
} |
||||
ExampleMandA(ExampleMandA &&e) : value(e.value) { |
||||
cout << "Called ExampleMandA move constructor with value " << value << ".." << endl; |
||||
e.value = 0; |
||||
} |
||||
~ExampleMandA() { |
||||
cout << "Called ExampleMandA destructor (" << value << ")" << endl; |
||||
} |
||||
std::string toString() { |
||||
return "ExampleMandA[value=" + std::to_string(value) + "]"; |
||||
} |
||||
|
||||
void operator=(const ExampleMandA &e) { cout << "Assignment operator" << endl; value = e.value; } |
||||
void operator=(ExampleMandA &&e) { cout << "Move assignment operator" << endl; value = e.value; e.value = 0;} |
||||
|
||||
void add1(ExampleMandA other) { value += other.value; } // passing by value
|
||||
void add2(ExampleMandA &other) { value += other.value; } // passing by reference
|
||||
void add3(const ExampleMandA &other) { value += other.value; } // passing by const reference
|
||||
void add4(ExampleMandA *other) { value += other->value; } // passing by pointer
|
||||
void add5(const ExampleMandA *other) { value += other->value; } // passing by const pointer
|
||||
|
||||
void add6(int other) { value += other; } // passing by value
|
||||
void add7(int &other) { value += other; } // passing by reference
|
||||
void add8(const int &other) { value += other; } // passing by const reference
|
||||
void add9(int *other) { value += *other; } // passing by pointer
|
||||
void add10(const int *other) { value += *other; } // passing by const pointer
|
||||
|
||||
ExampleMandA self1() { return *this; } // return by value
|
||||
ExampleMandA &self2() { return *this; } // return by reference
|
||||
const ExampleMandA &self3() { return *this; } // return by const reference
|
||||
ExampleMandA *self4() { return this; } // return by pointer
|
||||
const ExampleMandA *self5() { return this; } // return by const pointer
|
||||
|
||||
int internal1() { return value; } // return by value
|
||||
int &internal2() { return value; } // return by reference
|
||||
const int &internal3() { return value; } // return by const reference
|
||||
int *internal4() { return &value; } // return by pointer
|
||||
const int *internal5() { return &value; } // return by const pointer
|
||||
|
||||
int value = 0; |
||||
}; |
||||
|
||||
void init_ex_methods_and_attributes(py::module &m) { |
||||
py::class_<ExampleMandA>(m, "ExampleMandA") |
||||
.def(py::init<>()) |
||||
.def(py::init<int>()) |
||||
.def(py::init<const ExampleMandA&>()) |
||||
.def("add1", &ExampleMandA::add1) |
||||
.def("add2", &ExampleMandA::add2) |
||||
.def("add3", &ExampleMandA::add3) |
||||
.def("add4", &ExampleMandA::add4) |
||||
.def("add5", &ExampleMandA::add5) |
||||
.def("add6", &ExampleMandA::add6) |
||||
.def("add7", &ExampleMandA::add7) |
||||
.def("add8", &ExampleMandA::add8) |
||||
.def("add9", &ExampleMandA::add9) |
||||
.def("add10", &ExampleMandA::add10) |
||||
.def("self1", &ExampleMandA::self1) |
||||
.def("self2", &ExampleMandA::self2) |
||||
.def("self3", &ExampleMandA::self3) |
||||
.def("self4", &ExampleMandA::self4) |
||||
.def("self5", &ExampleMandA::self5) |
||||
.def("internal1", &ExampleMandA::internal1) |
||||
.def("internal2", &ExampleMandA::internal2) |
||||
.def("internal3", &ExampleMandA::internal3) |
||||
.def("internal4", &ExampleMandA::internal4) |
||||
.def("internal5", &ExampleMandA::internal5) |
||||
.def("__str__", &ExampleMandA::toString) |
||||
.def_readwrite("value", &ExampleMandA::value); |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
Called ExampleMandA default constructor.. |
||||
Called ExampleMandA constructor with value 32.. |
||||
Called ExampleMandA copy constructor with value 32.. |
||||
Called ExampleMandA copy constructor with value 32.. |
||||
Called ExampleMandA destructor (32) |
||||
Called ExampleMandA destructor (32) |
||||
Instance 1: ExampleMandA[value=320] |
||||
Instance 2: ExampleMandA[value=32] |
||||
Called ExampleMandA copy constructor with value 320.. |
||||
Called ExampleMandA move constructor with value 320.. |
||||
Called ExampleMandA destructor (0) |
||||
ExampleMandA[value=320] |
||||
Called ExampleMandA destructor (320) |
||||
ExampleMandA[value=320] |
||||
ExampleMandA[value=320] |
||||
ExampleMandA[value=320] |
||||
ExampleMandA[value=320] |
||||
320 |
||||
320 |
||||
320 |
||||
320 |
||||
320 |
||||
Instance 1, direct access = 320 |
||||
Instance 1: ExampleMandA[value=100] |
||||
Called ExampleMandA destructor (32) |
||||
Called ExampleMandA destructor (100) |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python |
||||
from __future__ import print_function |
||||
import sys |
||||
sys.path.append('.') |
||||
|
||||
from example import ExampleVirt, runExampleVirt, runExampleVirtVirtual, runExampleVirtBool |
||||
|
||||
|
||||
class ExtendedExampleVirt(ExampleVirt): |
||||
def __init__(self, state): |
||||
super(ExtendedExampleVirt, self).__init__(state + 1) |
||||
self.data = "Hello world" |
||||
|
||||
def run(self, value): |
||||
print('ExtendedExampleVirt::run(%i), calling parent..' % value) |
||||
return super(ExtendedExampleVirt, self).run(value + 1) |
||||
|
||||
def run_bool(self): |
||||
print('ExtendedExampleVirt::run_bool()') |
||||
return False |
||||
|
||||
def pure_virtual(self): |
||||
print('ExtendedExampleVirt::pure_virtual(): %s' % self.data) |
||||
|
||||
|
||||
ex12 = ExampleVirt(10) |
||||
print(runExampleVirt(ex12, 20)) |
||||
try: |
||||
runExampleVirtVirtual(ex12) |
||||
except Exception as e: |
||||
print("Caught expected exception: " + str(e)) |
||||
|
||||
ex12p = ExtendedExampleVirt(10) |
||||
print(runExampleVirt(ex12p, 20)) |
||||
print(runExampleVirtBool(ex12p)) |
||||
runExampleVirtVirtual(ex12p) |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
Constructing ExampleVirt.. |
||||
Original implementation of ExampleVirt::run(state=10, value=20) |
||||
30 |
||||
Caught expected exception: Tried to call pure virtual function "ExampleVirt::pure_virtual" |
||||
Constructing ExampleVirt.. |
||||
ExtendedExampleVirt::run(20), calling parent.. |
||||
Original implementation of ExampleVirt::run(state=11, value=21) |
||||
32 |
||||
ExtendedExampleVirt::run_bool() |
||||
False |
||||
ExtendedExampleVirt::pure_virtual(): Hello world |
||||
Destructing ExampleVirt.. |
||||
Destructing ExampleVirt.. |
@ -1,92 +0,0 @@
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
example/example1.cpp -- constructors, deconstructors, attribute access, |
||||
__str__, argument and return value conventions |
||||
|
||||
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> |
||||
|
||||
All rights reserved. Use of this source code is governed by a |
||||
BSD-style license that can be found in the LICENSE file. |
||||
*/ |
||||
|
||||
#include "example.h" |
||||
|
||||
class Example1 { |
||||
public: |
||||
Example1() { |
||||
cout << "Called Example1 default constructor.." << endl; |
||||
} |
||||
Example1(int value) : value(value) { |
||||
cout << "Called Example1 constructor with value " << value << ".." << endl; |
||||
} |
||||
Example1(const Example1 &e) : value(e.value) { |
||||
cout << "Called Example1 copy constructor with value " << value << ".." << endl; |
||||
} |
||||
Example1(Example1 &&e) : value(e.value) { |
||||
cout << "Called Example1 move constructor with value " << value << ".." << endl; |
||||
e.value = 0; |
||||
} |
||||
~Example1() { |
||||
cout << "Called Example1 destructor (" << value << ")" << endl; |
||||
} |
||||
std::string toString() { |
||||
return "Example1[value=" + std::to_string(value) + "]"; |
||||
} |
||||
|
||||
void operator=(const Example1 &e) { cout << "Assignment operator" << endl; value = e.value; } |
||||
void operator=(Example1 &&e) { cout << "Move assignment operator" << endl; value = e.value; e.value = 0;} |
||||
|
||||
void add1(Example1 other) { value += other.value; } // passing by value
|
||||
void add2(Example1 &other) { value += other.value; } // passing by reference
|
||||
void add3(const Example1 &other) { value += other.value; } // passing by const reference
|
||||
void add4(Example1 *other) { value += other->value; } // passing by pointer
|
||||
void add5(const Example1 *other) { value += other->value; } // passing by const pointer
|
||||
|
||||
void add6(int other) { value += other; } // passing by value
|
||||
void add7(int &other) { value += other; } // passing by reference
|
||||
void add8(const int &other) { value += other; } // passing by const reference
|
||||
void add9(int *other) { value += *other; } // passing by pointer
|
||||
void add10(const int *other) { value += *other; } // passing by const pointer
|
||||
|
||||
Example1 self1() { return *this; } // return by value
|
||||
Example1 &self2() { return *this; } // return by reference
|
||||
const Example1 &self3() { return *this; } // return by const reference
|
||||
Example1 *self4() { return this; } // return by pointer
|
||||
const Example1 *self5() { return this; } // return by const pointer
|
||||
|
||||
int internal1() { return value; } // return by value
|
||||
int &internal2() { return value; } // return by reference
|
||||
const int &internal3() { return value; } // return by const reference
|
||||
int *internal4() { return &value; } // return by pointer
|
||||
const int *internal5() { return &value; } // return by const pointer
|
||||
|
||||
int value = 0; |
||||
}; |
||||
|
||||
void init_ex1(py::module &m) { |
||||
py::class_<Example1>(m, "Example1") |
||||
.def(py::init<>()) |
||||
.def(py::init<int>()) |
||||
.def(py::init<const Example1&>()) |
||||
.def("add1", &Example1::add1) |
||||
.def("add2", &Example1::add2) |
||||
.def("add3", &Example1::add3) |
||||
.def("add4", &Example1::add4) |
||||
.def("add5", &Example1::add5) |
||||
.def("add6", &Example1::add6) |
||||
.def("add7", &Example1::add7) |
||||
.def("add8", &Example1::add8) |
||||
.def("add9", &Example1::add9) |
||||
.def("add10", &Example1::add10) |
||||
.def("self1", &Example1::self1) |
||||
.def("self2", &Example1::self2) |
||||
.def("self3", &Example1::self3) |
||||
.def("self4", &Example1::self4) |
||||
.def("self5", &Example1::self5) |
||||
.def("internal1", &Example1::internal1) |
||||
.def("internal2", &Example1::internal2) |
||||
.def("internal3", &Example1::internal3) |
||||
.def("internal4", &Example1::internal4) |
||||
.def("internal5", &Example1::internal5) |
||||
.def("__str__", &Example1::toString) |
||||
.def_readwrite("value", &Example1::value); |
||||
} |
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
Called Example1 default constructor.. |
||||
Called Example1 constructor with value 32.. |
||||
Called Example1 copy constructor with value 32.. |
||||
Called Example1 copy constructor with value 32.. |
||||
Called Example1 destructor (32) |
||||
Called Example1 destructor (32) |
||||
Instance 1: Example1[value=320] |
||||
Instance 2: Example1[value=32] |
||||
Called Example1 copy constructor with value 320.. |
||||
Called Example1 move constructor with value 320.. |
||||
Called Example1 destructor (0) |
||||
Example1[value=320] |
||||
Called Example1 destructor (320) |
||||
Example1[value=320] |
||||
Example1[value=320] |
||||
Example1[value=320] |
||||
Example1[value=320] |
||||
320 |
||||
320 |
||||
320 |
||||
320 |
||||
320 |
||||
Instance 1, direct access = 320 |
||||
Instance 1: Example1[value=100] |
||||
Called Example1 destructor (32) |
||||
Called Example1 destructor (100) |
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
#!/usr/bin/env python |
||||
from __future__ import print_function |
||||
import sys |
||||
sys.path.append('.') |
||||
|
||||
from example import Example12, runExample12, runExample12Virtual, runExample12Bool |
||||
|
||||
|
||||
class ExtendedExample12(Example12): |
||||
def __init__(self, state): |
||||
super(ExtendedExample12, self).__init__(state + 1) |
||||
self.data = "Hello world" |
||||
|
||||
def run(self, value): |
||||
print('ExtendedExample12::run(%i), calling parent..' % value) |
||||
return super(ExtendedExample12, self).run(value + 1) |
||||
|
||||
def run_bool(self): |
||||
print('ExtendedExample12::run_bool()') |
||||
return False |
||||
|
||||
def pure_virtual(self): |
||||
print('ExtendedExample12::pure_virtual(): %s' % self.data) |
||||
|
||||
|
||||
ex12 = Example12(10) |
||||
print(runExample12(ex12, 20)) |
||||
try: |
||||
runExample12Virtual(ex12) |
||||
except Exception as e: |
||||
print("Caught expected exception: " + str(e)) |
||||
|
||||
ex12p = ExtendedExample12(10) |
||||
print(runExample12(ex12p, 20)) |
||||
print(runExample12Bool(ex12p)) |
||||
runExample12Virtual(ex12p) |
@ -1,13 +0,0 @@
@@ -1,13 +0,0 @@
|
||||
Constructing Example12.. |
||||
Original implementation of Example12::run(state=10, value=20) |
||||
30 |
||||
Caught expected exception: Tried to call pure virtual function "Example12::pure_virtual" |
||||
Constructing Example12.. |
||||
ExtendedExample12::run(20), calling parent.. |
||||
Original implementation of Example12::run(state=11, value=21) |
||||
32 |
||||
ExtendedExample12::run_bool() |
||||
False |
||||
ExtendedExample12::pure_virtual(): Hello world |
||||
Destructing Example12.. |
||||
Destructing Example12.. |
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
example/example16.cpp -- automatic upcasting for polymorphic types |
||||
|
||||
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> |
||||
|
||||
All rights reserved. Use of this source code is governed by a |
||||
BSD-style license that can be found in the LICENSE file. |
||||
*/ |
||||
|
||||
#include "example.h" |
||||
|
||||
struct BaseClass { virtual ~BaseClass() {} }; |
||||
struct DerivedClass1 : BaseClass { }; |
||||
struct DerivedClass2 : BaseClass { }; |
||||
|
||||
void init_ex16(py::module &m) { |
||||
py::class_<BaseClass>(m, "BaseClass").def(py::init<>()); |
||||
py::class_<DerivedClass1>(m, "DerivedClass1").def(py::init<>()); |
||||
py::class_<DerivedClass2>(m, "DerivedClass2").def(py::init<>()); |
||||
|
||||
m.def("return_class_1", []() -> BaseClass* { return new DerivedClass1(); }); |
||||
m.def("return_class_2", []() -> BaseClass* { return new DerivedClass2(); }); |
||||
m.def("return_none", []() -> BaseClass* { return nullptr; }); |
||||
} |
@ -1,5 +0,0 @@
@@ -1,5 +0,0 @@
|
||||
from example import example18 |
||||
|
||||
example18() |
||||
|
||||
|
@ -1,58 +0,0 @@
@@ -1,58 +0,0 @@
|
||||
#!/usr/bin/env python |
||||
from __future__ import print_function |
||||
import sys |
||||
sys.path.append('.') |
||||
|
||||
from example import test_function |
||||
from example import some_constant |
||||
from example import EMyEnumeration |
||||
from example import EFirstEntry |
||||
from example import Example4 |
||||
from example import return_bytes |
||||
from example import print_bytes |
||||
|
||||
print(EMyEnumeration) |
||||
print(EMyEnumeration.EFirstEntry) |
||||
print(EMyEnumeration.ESecondEntry) |
||||
print(EFirstEntry) |
||||
|
||||
print(test_function()) |
||||
print(test_function(7)) |
||||
print(test_function(EMyEnumeration.EFirstEntry)) |
||||
print(test_function(EMyEnumeration.ESecondEntry)) |
||||
print("enum->integer = %i" % int(EMyEnumeration.ESecondEntry)) |
||||
print("integer->enum = %s" % str(EMyEnumeration(2))) |
||||
|
||||
print("A constant = " + str(some_constant)) |
||||
|
||||
print(Example4.EMode) |
||||
print(Example4.EMode.EFirstMode) |
||||
print(Example4.EFirstMode) |
||||
Example4.test_function(Example4.EFirstMode) |
||||
|
||||
print("Equality test 1: " + str( |
||||
Example4.test_function(Example4.EFirstMode) == |
||||
Example4.test_function(Example4.EFirstMode))) |
||||
|
||||
print("Inequality test 1: " + str( |
||||
Example4.test_function(Example4.EFirstMode) != |
||||
Example4.test_function(Example4.EFirstMode))) |
||||
|
||||
print("Equality test 2: " + str( |
||||
Example4.test_function(Example4.EFirstMode) == |
||||
Example4.test_function(Example4.ESecondMode))) |
||||
|
||||
print("Inequality test 2: " + str( |
||||
Example4.test_function(Example4.EFirstMode) != |
||||
Example4.test_function(Example4.ESecondMode))) |
||||
|
||||
x = { |
||||
Example4.test_function(Example4.EFirstMode): 1, |
||||
Example4.test_function(Example4.ESecondMode): 2 |
||||
} |
||||
|
||||
x[Example4.test_function(Example4.EFirstMode)] = 3 |
||||
x[Example4.test_function(Example4.ESecondMode)] = 4 |
||||
print("Hashing test = " + str(x)) |
||||
|
||||
print_bytes(return_bytes()) |
Loading…
Reference in new issue