How to modify this from Python 2.x to v3.4?

jfong at ms4.hinet.net jfong at ms4.hinet.net
Sat Nov 11 06:56:11 EST 2017


I learned python start from using v3.4 and never has any v2.x experience. There is a Pypi project "ctypesgen" I like to use, but it seems is for v2.x. (un)Fortunately I found one of its branch on github which announced is for Python3, but strangely it still use some v2.x words, for example, print. Its last update was at July 2009, maybe at the early age of v3? The one below which I can't figure out how to modify. Can someone show me the answer? (I don't want to spend time on learning the old history:-)

---------------------
# Available instance types.  This is used when lexers are defined by a class.
# It's a little funky because I want to preserve backwards compatibility
# with Python 2.0 where types.ObjectType is undefined.

try:
   _INSTANCETYPE = (types.InstanceType, types.ObjectType)
except AttributeError:
   _INSTANCETYPE = types.InstanceType
   class object: pass       # Note: needed if no new-style classes present
...
...
...
    if module:
        # User supplied a module object.
        if isinstance(module, types.ModuleType):
            ldict = module.__dict__
        elif isinstance(module, _INSTANCETYPE):
            _items = [(k,getattr(module,k)) for k in dir(module)]
...
...
---------------

Best Regards,
Jach Fong



More information about the Python-list mailing list