Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Parameters defaulting to None

$
0
0
In my constructor, the name and description parameters are supposed to default to None if they are not entered. I think I have that part set up correctly. If name isn't entered and defaults to None, a ValueError is thrown:

    def __init__(self, name = None, methodCount, locCount, description = None):
        
        if(name == None):
            raise ValueError("Stats.__init__: invalid parm")
        else:
            self.theName = name
            
        if(description != None):
            self.theDescription = description
            
        self.theMethodCount = methodCount
        self.theLocCount = locCount



My question is, how does my constructor know which parameters are left out? I know Python is dynamically typed, so if I left out the name, wouldn't it think that methodCount is actually name? How would I pass this?

myStats = stats.Stats(3,15)



Would it automatically, from the statement above, set name and description to None?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>