To change the line 117 to "if otype is dict:" is not quite correct. Correct is "if isinstance(otype, dict):", because type checking has to be done by using the isinstance() built-in method.
I'll try to come up with a patch. Stay tuned. :)ile "C:\Program Files\Python 3.3.2\lib\site-packages\wx\py\filling.py",
···
line 108, in objHasChildren
if self.objGetChildren(obj):
File "C:\Program Files\Python 3.3.2\lib\site-packages\wx\py\filling.py",
line 117, in objGetChildren
if otype is types.DictType \
AttributeError: 'module' object has no attribute 'DictType'
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I was using the faster correction that worked (I think lib2to3 also uses this translation) .
Now I realize it is not the recommended, correct one.
Thanks
Joaquin
···
On Sunday, May 26, 2013 7:37:50 AM UTC+2, Boštjan Mejak wrote:
To change the line 117 to “if otype is dict:” is not quite correct. Correct is “if isinstance(otype, dict):”, because type checking has to be done by using the isinstance() built-in method.
I’ll try to come up with a patch. Stay tuned. :)ile “C:\Program Files\Python 3.3.2\lib\site-packages\wx\py\filling.py”,
line 108, in objHasChildren
if self.objGetChildren(obj):
File “C:\Program Files\Python 3.3.2\lib\site-packages\wx\py\filling.py”,
line 117, in objGetChildren
if otype is types.DictType \
AttributeError: ‘module’ object has no attribute ‘DictType’
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
Okay, so this is my first attempt to make WIT Python 3 compatible. However, it breaks Python 2 compatibility, but that’s something I need to dig into once I get a thumbs up from you guys.
Okay, so this is my first attempt to make WIT Python 3 compatible.
However, it breaks Python 2 compatibility, but that's something I need
to dig into once I get a thumbs up from you guys.
Any comments on my patch are welcome.
The changes like this one are not correct:
@@ -114,11 +114,11 @@ class FillingTree(wx.TreeCtrl):
"""Return dictionary with attributes or contents of object."""
busy = wx.BusyCursor()
otype = type(obj)
- if otype is types.DictType \
+ if isinstance(otype, dict) \
or str(otype)[17:23] == 'BTrees' and hasattr(obj, 'keys'):
return obj
d = {}
- if otype is types.ListType or otype is types.TupleType:
+ if isinstance(otype, list) or isinstance(otype, tuple):
for n in range(len(obj)):
key = '[' + str(n) + ']'
d[key] = obj[n]
otype is a type object, not something that can be an instance of a dictionary. You should check isinstance(obj, dict) instead.
On Python 2 compatibility, it only needs to stay compatible with Python 2.7, so feel free to use any compatibility helps or __future__'s that will help to write code that is compatible with both. See the ProjectPhoenix/LibraryMigration - wxPyWiki page in the wiki for more info.
maybe:
keys.sort(key=lambda x: str(x).lower())
but this is not compatible with pythont 2.
In porting to python 3 Regebro recommends to use a helper function:
def cmp(a, b):
return (a > b) - (a < b)
J
Hi,
I don't know the context of the relevant source code, but the "key"
argument for sorting functions is perfectly valid in py 2.7;
cf.:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit
(Intel)] on win32
...
keys = ["a","D","A","b"]
keys.sort(); keys
['A', 'D', 'a', 'b']
keys.sort(key=lambda x: x.lower()); keys
['A', 'a', 'b', 'D']
if the str(...) call is needed, probably an appropriate alias from the
"six" module could be used (probably six.text_type).
hth,
vbr
···
On Monday, May 27, 2013 10:33:25 PM UTC+2, Boštjan Mejak wrote:
On Mon, May 27, 2013 at 10:12 PM, Robin Dunn <ro...@alldunn.com> wrote: