Index: /pyyaml/trunk/lib/yaml/representer.py
===================================================================
--- /pyyaml/trunk/lib/yaml/representer.py	(revision 147)
+++ /pyyaml/trunk/lib/yaml/representer.py	(revision 148)
@@ -242,4 +242,7 @@
         else:
             state = data.__dict__.copy()
+        if isinstance(state, dict):
+            state = state.items()
+            state.sort()
         return self.represent_mapping(tag, state, flow_style=flow_style)
 
@@ -373,4 +376,6 @@
             state = data.__dict__
         if args is None and isinstance(state, dict):
+            state = state.items()
+            state.sort()
             return self.represent_mapping(
                     u'tag:yaml.org,2002:python/object:'+class_name, state)
@@ -431,4 +436,6 @@
         if not args and not listitems and not dictitems \
                 and isinstance(state, dict) and newobj:
+            state = state.items()
+            state.sort()
             return self.represent_mapping(
                     u'tag:yaml.org,2002:python/object:'+function_name, state)
