Well, it did work correctly, but that's probably due to how I was testing it before(re-running the script manually after it ran once), this was the first time I was in a situation where I was recalling the same function without just starting the program from scratch.
Basically, I created a situation for myself that made it very hard to debug. On the bright side, Python's my first experience with OO programming and I just started playing with it this week, so I learned some valuable lessons that'll help me in the future. On Jun 28, 7:41 pm, Branko Vukelic <[email protected]> wrote: > Hm... I thought you said your function did work correctly when not > using Templetor for constructing the output. Otherwise, I would have > told you to check the time and some other vars in there... :) > > > > > > > > > > On Wed, Jun 29, 2011 at 2:27 AM, ckdehg <[email protected]> wrote: > > The problem was that I'm new to OO programming and didn't consider > > that my time variable was out of scope of the casecount() function, so > > it wasn't updating everytime the function was re-running. Since none > > of the other data was changing, it was hard to spot (but in > > retrospect, that should have made it easier to spot). Regardless, > > thanks for the help! > > > On Jun 28, 4:56 pm, ckdehg <[email protected]> wrote: > >> Not sure I follow. When I do the return in the function, I am > >> enclosing it in three single quotes, which should be the same as three > >> double quotes? I changed it anyways and had the same result. > > >> On Jun 28, 9:58 am, Greg Milby <[email protected]> wrote: > > >> > Try return in buffer string? """String here""" > > >> > ::Sent from my Verizon HTC Incredible Android:: > >> > On Jun 28, 2011 7:49 AM, "ckdehg" <[email protected]> wrote: > > >> > > Like the title says, I'm having issues with web.py. > > >> > > I have a script that starts a web.py instance and is serving basic > >> > > pages. Using the web.py template system, I'm able to get functions > >> > > like time.time() to refresh every time I reload(meaning, when I > >> > > refresh, the time printed has increased). However, I have a self > >> > > written function that performs some math and returns a multiline > >> > > string. When the function is called either from a script or on the > >> > > command line, it returns a different value each time, however, when I > >> > > call it using the web.py templating system, it seems to only run the > >> > > function once, and then will not re-run it again on additional page > >> > > reloads (even though time.time() updates each time). The only way to > >> > > get it to re-run is to restart the script. > > >> > > Here's the function in question: > > >> > > def casecount(): > >> > > curcount = 80 > >> > > sc = startcount(date) > >> > > delta = sc - curcount > >> > > pace = float(delta) / float(ElTime(time, "9:00")) > >> > > eta = float(curcount) / float(pace) > >> > > return '''We started with %d cases as of 9AM<br> > >> > > Remaining cases as of %s: %d<br> > >> > > We\'re working at a pace of %.3f cases per hour. At this rate, > >> > > we will finish in approximately %.3f hours<br>''' % (sc, time, > >> > > curcount, pace, eta) > >> > > Obviously there are other functions I've written that the script > >> > > calls, but I know for a fact that it works when run on its own. > > >> > > I'm providing function access to the web.py templating system using > >> > > this code: > > >> > > render = web.template.render('templates/', cache=False, > >> > > globals={'cc': casecount, 'time': time} ) > >> > > and finally, I'm calling the code in the template with this: > > >> > > <html> > >> > > <head> > >> > > </head> > >> > > <body> > >> > > $time() > >> > > $cc() > >> > > </body> > >> > > </html> > >> > > Any ideas? I've been at it for a while and have searched google to no > >> > > avail. > > >> > > -- > >> > > You received this message because you are subscribed to the Google > >> > > Groups > >> > "web.py" group. > >> > > To post to this group, send email to [email protected]. > >> > > To unsubscribe from this group, send email to > > >> > [email protected].> For more options, visit this group > >> > at > > >> >http://groups.google.com/group/webpy?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "web.py" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/webpy?hl=en. > > -- > Branko Vukelić > [email protected] > > Lead Developer > Herd Hound (tm) - Travel that doesn't bitewww.herdhound.com -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
