Re: Making functions callable

2014-03-26 Thread Anthony Hawkes
Thanks Guys, especially Javier! I've spent so much time trawling Google for this info! On Thursday, 27 March 2014 04:57:30 UTC+8, Anthony Hawkes wrote: > > Hi Guys, > > I'm running into a problem with django(I guess this would also affect > Python in general) where if I create a view eg > def

Re: Making functions callable

2014-03-26 Thread Javier Guerra Giraldez
On Wed, Mar 26, 2014 at 5:53 PM, Anthony wrote: > I've yet to test it but I read a few people stating to use lambdas > variables/properties. Is it definitely the case that it will only evaluate > once? from the python docs (2.7): Default parameter values are evaluated

Re: Making functions callable

2014-03-26 Thread John DeRosa
Not sure what is going on without seeing the code. But something is None when it should be a string, as the exception is telling you. It's often easiest to try out problem code interactively in Python, and zero in on the problem. John On Mar 26, 2014, at 3:53 PM, Anthony

Re: Making functions callable

2014-03-26 Thread Mike Dewhirst
On 27/03/2014 7:57am, Anthony Hawkes wrote: Hi Guys, I'm running into a problem with django(I guess this would also affect Python in general) where if I create a view eg def view(year=today.year()) The year is never re-evaluated until the server is reloaded/restarted I'm trying to figure out

Re: Making functions callable

2014-03-26 Thread Anthony
Thanks John, I've yet to test it but I read a few people stating to use lambdas variables/properties. Is it definitely the case that it will only evaluate once? Either way I've embarked on the mission to make methods return as properties and have found @property decorator to fit my needs, the

Re: Making functions callable

2014-03-26 Thread John DeRosa
For the default value to work as you expect, do this: def view(request, year=None): if year is None: year = today.year() Kwarg defaults are evaluated when the module is interpreted for the first time. John On Mar 26, 2014, at 1:57 PM, Anthony Hawkes

Making functions callable

2014-03-26 Thread Anthony Hawkes
Hi Guys, I'm running into a problem with django(I guess this would also affect Python in general) where if I create a view eg def view(year=today.year()) The year is never re-evaluated until the server is reloaded/restarted I'm trying to figure out how to make a callable method accessible as a