I have an interesting issue with having an optional argument to a function that is an property of a class:
I want to do the following
def addStockToMarket(self, stockTicker, startDate=self.tradingDay):
where tradingDay is a property of the class that is set when the class object is constructed. the issue is that it doesnt like that i am doing that because i guess it doesnt know what "self" is at that point in the function definition since it is getting self passed into it.
is there any way around this issue other than making seperate functions for each set of arguments?
Hey like something i said? Helped you out? Or you just like supporting the Random Guy?
add to my rep. its quick and easy and definitely wont steal your girlfriend.
In fact, that's the generally recommended method, and you can add more conditions there to verify the validity of the argument.
Since "None" probably wont be a valid date, you can just write:Code:def addStockToMarket(self, stockTicker, startDate=None): if startDate == None or not isValidDate(startDate): startDate = self.tradingDay
Code:if not isValidDate(startDate): startDate = self.tradingDay
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks