attempt to use str() to get object name
lots of things possibly wrong with this
- i don't know if this works on python2.7
- i don't know if this is a good fix
- i don't know what this might break
- i did not run it through any testsuite (does a testsuite exist? if it does, i am unaware)
- i don't know if str(object) even can throw (i just assumed it was a possibility and added fallback to the old method if it does throw)
however, previously this
import ctypes
import ctypes.wintypes
from var_dump import var_dump
foo = ctypes.wintypes.ULARGE_INTEGER(123)
print(foo)
var_dump(foo)
would produce
c_ulonglong(123)
#0 object(c_ulonglong) (0)
and print() actually did a better job than var_dump() here, but now it produce:
c_ulonglong(123)
#0 object(c_ulonglong(123)) (0)
doing at least as good a job as print :)
this also fixes ctypes.wintypes.HANDLE which has the same problem as ctypes.wintypes.ULARGE_INTEGER
this fixes #15 and is an alternative to #16 (eg either #16 or #17 should be merged, but not both)
this has another interesting side effect, the sample code in README.md (after fixing the tab errors in #18 ) now prints:
#0 object(<__main__.Foo object at 0x00000230C350FEE0>) (6)
baseProp => tuple(2)
[0] => int(33)
[1] => int(44)
fl => float(44.33)
someList => list(2)
[0] => str(3) "foo"
[1] => str(3) "goo"
someTuple => tuple(3)
[0] => int(33)
[1] => tuple(2)
[0] => int(23)
[1] => int(44)
[2] => int(55)
anOb => object(<__main__.Bar object at 0x00000230C350FBE0>) (2)
barProp => str(18) "I'm from Bar class"
boo => bool(True)
no => NoneType(None)
instead of the old
#0 object(Foo) (6)
baseProp => tuple(2)
[0] => int(33)
[1] => int(44)
fl => float(44.33)
someList => list(2)
[0] => str(3) "foo"
[1] => str(3) "goo"
someTuple => tuple(3)
[0] => int(33)
[1] => tuple(2)
[0] => int(23)
[1] => int(44)
[2] => int(55)
anOb => object(Bar) (2)
barProp => str(18) "I'm from Bar class"
boo => bool(True)
no => NoneType(None)
not saying its better or worse, but it certainly is a bit different.
(My personal opinion is that this is an improvement, because now you can see where the class is defined and you can differentiate between __main__.SomeClassWithDuplicateName and SomethingElse.SomeClassWithDuplicateName , but i also see how it contains info that 99% of the time people just don't care about, and perhaps, don't want to see)