why does this hang

Doug Fort doug.fort at verizon.net
Thu Aug 16 20:44:54 EDT 2001


John Hunter wrote:

> 
> 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())
> 
> 
> 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?
> 
> Thanks,
> John Hunter
> 
The formatted string is looking for a tuple or a dictionary following the 
'%'. It's not a case of '%' binding more tightly than '.'. By using the 
parentheses you are converting the output of the function to a tuple. I'm 
not too hip to Python internals, but I suspect the interpreter is trying to 
get a tuple from the address of the get_mdy() member, rather than calling 
the function. I like to use the form ... % (d.get_tomorrow().get_mdy(),) to 
make it explicit that it's a tuple.
-- 
Doug Fort <dougfort at dougfort.net>
http://www.dougfort.net

______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
   With Seven Servers In California And Texas - The Worlds Uncensored News Source
  



More information about the Python-list mailing list