why does this hang
Alex Martelli
aleaxit at yahoo.com
Fri Aug 17 03:11:47 EDT 2001
"John Hunter" <jdhunter at nitace.bsd.uchicago.edu> wrote in message
news:1r66bnzkc6.fsf at video.bsd.uchicago.edu...
>
> I have a class member function that returns a member of that class,
> namely a date class that returns 'tomorrow'
>
> from Trade import MyDate
>
> d = MyDate()
> #mdy is month/day/year as a string
> print 'today is %s' % d.get_mdy()
> print 'tomorrow is %s' % (d.get_tomorrow().get_mdy())
Here's a reproduction of your code which includes a toy
implementation for the MyDate class:
import time
class MyDate:
def __init__(self, when=None):
if when is None: self.time = time.time()
else: self.time = when
def get_tomorrow(self):
return self.__class__(self.time+86400)
def get_mdy(self):
return time.strftime("%Y/%m/%d",time.gmtime(self.time))
d = MyDate()
print 'today is %s' % d.get_mdy()
print 'tomorrow is %s' % (d.get_tomorrow().get_mdy())
print 'tomorrow is %s' % d.get_tomorrow().get_mdy()
> If I don't put the parens around 'd.get_tomorrow().get_mdy()' the code
> hangs (totally frozen, no response to Ctrl-C on a linux box)
>
> Does the % operator bind more tightly than the '.' operator? Is this
> expected?
Absolutely not. On my test code:
D:\py21>python pk.py
today is 2001/08/17
tomorrow is 2001/08/18
tomorrow is 2001/08/18
So, there must be something very peculiar with your date class,
or some other change besides omitting parentheses in the line
that's failing for you.
Alex
More information about the Python-list
mailing list