Test an object is a subclass of the type of another instance

You’d need to extract the type of obj with the type() function: isinstance(obj2, type(obj1)) Note that the second argument is the class, the first is the instance to test. type() is returning the actual class object here, not any separate object. issubclass() works just fine for your usecase: issubclass(type(obj2), Item) Demo: >>> class Item: … … Read more

cx-freeze, runpy and multiprocessing – multiple paths to failure

I used cx_freeze for a project at work. I’m not sure if this is your problem… but I was using the Anaconda distribution, and cx_freeze was not properly gathering the .dll’s that I needed for my project. The solution was to: Install a plane version of Python make an environment with the packages that I … Read more

How to list all exceptions a function could raise in Python 3?

You can’t get reliable results for some (if not most) functions. Some examples: functions that execute arbitrary code (e.g. exec(‘)(rorrEeulaV esiar'[::-1]) raises ValueError) functions that aren’t written in Python functions that call other functions that can propagate errors to the caller functions re-raising active exceptions in the except: block Unfortunately, this list is incomplete. E.g. … Read more

Why does the asyncio’s event loop suppress the KeyboardInterrupt on Windows?

There is workaround for Windows. Run another corouting which wake up loop every second and allow loop to react on keyboard interrupt Example with Echo server from asyncio doc async def wakeup(): while True: await asyncio.sleep(1) loop = asyncio.get_event_loop() coro = loop.create_server(EchoServerClientProtocol, ‘127.0.0.1’, 8888) server = loop.run_until_complete(coro) # add wakeup HACK loop.create_task(wakeup()) try: loop.run_forever() except … Read more

lxml.etree.XML ValueError for Unicode string

data = open(module_path+’/data/ex-fire.xslt’) xslt_content = data.read() This implicitly decodes the bytes in the file to Unicode text, using the default encoding. (This might give wrong results, if the XML file isn’t in that encoding.) xslt_root = etree.XML(xslt_content) XML has its own handling and signalling for encodings, the <?xml encoding=”…”?> prolog. If you pass a Unicode … Read more

normalize non-existing path using pathlib only

is it possible to normalize a path to a file or directory that does not exist? Starting from 3.6, it’s the default behavior. See https://docs.python.org/3.6/library/pathlib.html#pathlib.Path.resolve Path.resolve(strict=False) … If strict is False, the path is resolved as far as possible and any remainder is appended without checking whether it exists

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)