Dec-23-2019, 05:13 PM
(This post was last modified: Dec-23-2019, 05:13 PM by Gribouillis.)
The
It would be a good idea to include an example of a typical input file if you can do that.
__repr__
gives a nice representation of the object when you try to display it, for example>>> class Statement: ... def __init__(self, data): ... self.data = data ... def __repr__(self): ... return "{}({})".format(self.__class__.__name__, self.data) ... >>> class Storey(Statement): ... pass ... >>> element = Storey(('STOREY', 'foo', 'BAR', 'baz')) >>> >>> element Storey(('STOREY', 'foo', 'BAR', 'baz'))If I don't include the
__repr__
in the class definition, the element is displayed as so>>> class Statement: ... def __init__(self, data): ... self.data = data ... >>> class Storey(Statement): ... pass ... >>> element = Storey(('STOREY', 'foo', 'BAR', 'baz')) >>> element <__main__.Storey object at 0x7ff163ad3898>Using classes for the various statements will help you in the second step when you will transform these statements in the second language or in intermediary steps if you want to manipulate the data easily. To start with. you can simply define a subclass of Statement for each of the kinds of statements that you meet in the input file. For example if there are statements for doors, then use a class
class Door(Statement): passThese classes are empty for now but you will be free to add features to them later.
It would be a good idea to include an example of a typical input file if you can do that.