Re-raised exceptions in 2.7.3 -- stack trace missing

2012-05-14 Thread Oliver Beattie
Hi there

I'm tying to investigate a bit of a weird problem here. Basically, I've just 
upgraded Python (from 2.7.2 - 2.7.3) by way of an OS upgrade (Ubuntu), and now 
all the tracebacks I'm getting sent from my web app are looking like this:

http://dpaste.org/EgKJp/

As you can see, Django is correctly re-raising the exception, but the original 
stack trace is not there by way of sys.exc_info(). I've dug into the code a 
little and it seems fairly simple, exc_info is passed through logging.error 
from sys.exc_info() so I see no reason why this shouldn't work.

Bit perplexing, any idea what could cause this?

—Oliver
-- 
http://mail.python.org/mailman/listinfo/python-list


Custom class to a dictionary?

2008-01-26 Thread Oliver Beattie
Just wondering if it is possible to pass a custom class instance
instance to dict() by way of using methods like you can for iterators
(__iter__, __getitem__ etc.) I see there is no __dict__ -- is there
anything else I can use to achieve this?

Kind Regards,
Oliver
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Custom class to a dictionary?

2008-01-26 Thread Oliver Beattie
On Jan 26, 12:01 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Sat, 26 Jan 2008 03:35:18 -0800, Oliver Beattie wrote:
  Just wondering if it is possible to pass a custom class instance
  instance to dict() by way of using methods like you can for iterators
  (__iter__, __getitem__ etc.) I see there is no __dict__ -- is there
  anything else I can use to achieve this?

 Just write a method to return (key, value) pairs, and call that:

  class Parrot(object):

 ...     def __init__(self):
 ...             self.keys = [1, 2, 3, 4]
 ...             self.values = [one, two, three, four]
 ...     def generate_tuples(self):
 ...             for k,v in zip(self.keys, self.values):
 ...                     yield (k,v)
 ... p = Parrot()
  p.generate_tuples()

 generator object at 0xb7d1d78c dict(p.generate_tuples())

 {1: 'one', 2: 'two', 3: 'three', 4: 'four'}

 Here's another way:

  class Foo(object):

 ...     def __getitem__(self, i):
 ...             if i  4:
 ...                     raise IndexError
 ...             return (i, 'foo %d' % i)
 ... dict(Foo())

 {0: 'foo 0', 1: 'foo 1', 2: 'foo 2', 3: 'foo 3', 4: 'foo 4'}

 Bonus marks if you can explain why they both work :)

 (Hint: consider the sequence protocol and the iterator protocol.)

 --
 Steven

Sure, I get what you're saying here and thanks for the advice; but I
don't want the keys as the iterator indices -- They should have custom
names (latitude, longitude and elevation). Is this possible (outside
of the custom method to generate two-tuples?) Sorry to be a pain!

The class looks like the below; I just whipped this up real quick but
it can generate the iterators it should -- just the dictionaries
should be different -- {'latitude': 0.0, 'longitude': 0.0,
'elevation': 0.0} or whatever):

class Coordinates(object):
Basic object for storing co-ordinate data.
latitude = 0.0
longitude = 0.0
elevation = 0.0

def __unicode__(self):
return u'Coordinate (%s, %s, %s)' % (self.latitude, 
self.longitude,
self.elevation)

def __repr__(self):
return 'Coordinates instance at (%s, %s, %s)' % 
(self.latitude,
self.longitude, self.elevation)

def __iter__(self):
return iter((self.latitude, self.longitude, self.elevation))

I guess it's just easier to have a dict() method to this end; just
wondered if there was a more 'Pythonic' way to do this.
-- 
http://mail.python.org/mailman/listinfo/python-list