Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Znav
nextPython Mapping for Sequences
prevPython Mapping for Enumerations

A Slice structure maps to a Python class with the same name. For each Slice data member, the Python class contains a corresponding attribute. For example, here is our Employee structure once more:

Wiki Markup
{zcode:slice}
struct Employee {
    long number;
    string firstName;
    string lastName;
};
{zcode}

The Python mapping generates the following definition for this structure:

Wiki Markup
{zcode:py}
class Employee(object):
    def __init__(self, number=0, firstName='', lastName=''):
        self.number = number
        self.firstName = firstName
        self.lastName = lastName

    def __hash__(self):
        # ...

    def __eq__(self, other):
        # ...

    def __str__(self):
        # ...
{zcode}

The constructor initializes each of the attributes to a default value appropriate for its type. You can also declare different default values for members of primitive and enumerated types.

The __hash__ method returns a hash value for the structure based on the value of all its data members.

The __eq__ method returns true if all members of two structures are (recursively) equal.

The __str__ method returns a string representation of the structure.

Ztop
See Also
Zret
Znav
nextPython Mapping for Sequences
prevPython Mapping for Enumerations