I have a method get_annotated_pkt_msg()
which takes a boolean parameter show_timestamp
. I want this to be an optional parameter, and so that if the caller doesn't specify an argument it will default to what is set in the user-defined config. This config is stored in container self.config
which has been passed-in by constructor dependency injection:
class XcpDaqFrame(XcpFrame):
def __init__(self, *args, **kwargs):
# Pass init arguments to super-class.
super(XcpDaqFrame, self).__init__(*args, **kwargs)
# Passed by dependency injection to this constructor.
self.config = config
def get_annotated_pkt_msg(
self,
show_timestamp=self.config.getConfigItem('display.packet_time')):
##### SyntaxError here ^ (on the dot after 'self') ########
"""Return the annotated packet message
:param bool show_timestamp:
:rtype: str
"""
# Optionally, show the timestamp of the packet.
if show_timestamp:
timestamp = get_timestamp()
timestamp_msg = u", Timestamp: {} μs".format(timestamp)
else:
timestamp_msg = ""
return timestamp_msg
frame = XcpDaqFrame(my_config)
frame.get_annotated_pkt_msg()
If I try the above it tells me, on the line marked above:
SyntaxError: invalid syntax
Why is it that I can pass self
to methods, but can't pass them self.config
?