Python Instance Variable as Default Parameter

Posted by DuneBug on Stack Overflow See other posts from Stack Overflow or by DuneBug
Published on 2010-05-14T00:19:32Z Indexed on 2010/05/14 0:24 UTC
Read the original article Hit count: 263

Filed under:


I have am writing a Python function that takes a timeout value as a parameter. Normally, the user will always use the same timeout value, but on occasion he may want to wait slightly longer. The timeout value is stored as a class instance variable. I want to use the class' timeout instance variable as the default parameter. Currently, I am implementing this as follows:

def _writeAndWait (self, string, timeout = -1):
    if (timeout == -1):
        timeout = self._timeout

I was just wondering, is the proper way to use an instance variable as a default parameter? Or is there a better way that would avoid the "if" check?



© Stack Overflow or respective owner

Related posts about python