Skip to main content

Posts

Why should I require all subclasses to call super() if I can use getmro to do it automatically?

I've read many of the other questions and opinions about super like super-harmful and super-considered-super but none of them mention inspect.getmro as an alternative. I'm wondering, instead of implementing a class hierarchy like this: class Base(object): def __init__(self, **kwargs): print("base init") class A(Base): def __init__(self, **kwargs): super(A, self).__init__() print("a init") class B(Base): def __init__(self, **kwargs): super(B, self).__init__() print("b init") class C(A, B): def __init__(self, **kwargs): super(C, self).__init__() print("c init") Why don't we do something like this? import inspect class Base(object): def __init__(self, **kwargs): mro = inspect.getmro(self.__class__) for mro_cls in reversed(mro): if hasattr(mro_cls, "_init"): mro_cls._init(self, **kwargs) def _init(self, **kwargs): print("base") class A(Bas

is there any way to get Django to read react components?

i am trying to import my react project to Django. I set up webpack, babel and finally all the backend ... But when I tried to import React's 'index.js' file it reads it successfully but fails to write it into the page's DOM. I tried testing the file without React and everything works fine, however, does anyone know how to give me some advice? Via Active questions tagged javascript - Stack Overflow https://ift.tt/ptlUGjN

Pycode segmentation fault when running from Docker container using XLaunch/XMing

i'd like to play around with pygame but i'd like to use a docker container to do so, but i can't render the pygame window on my host. I'm working on Windows 10 as host system and I've created a docker container with the image ''python'' (Debian 11); root@docker-desktop:/home# cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" I installed XMing/XLaunch on the host; I was able to connect the XLaunch/XMing window to the Docker container by setting the env variable DISPLAY=host.docker.internal:0.0 (i can run xcalc just fine, and python applications using tkinter) from tkinter import * window=Tk() # add widgets here window.title('Hello Python

activate verbose logging with reticulate package

Does anyone know how to activate verbose logging with reticulate package in R? I am trying to load my Python package into R with the following code: version <- "3.7.9" reticulate::install_python(version = version) reticulate::virtualenv_create("newssentiment-environment", version = version, packages = "NewsSentiment") reticulate::use_virtualenv("newssentiment-environment") NewsSentiment_p <<- reticulate::import("NewsSentiment", delay_load = TRUE) tsc <<- NewsSentiment_p$TargetSentimentClassifier() I have loaded the python environment into pycharm, and here the package installation has worked. Therefore, I am trying to see where the error in Rstudio lies. The installation of the package seems to work, I can see that all the package data is downloaded. Running the code with debugg, shows the error message: Error in py_module_import(module, convert = convert) : SystemExit: 1 I get the error message on my Win

Uncaught Error: Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid

I am working on a React project. Whenever I log out from the system, I get this error in the console. injectStylesIntoStyleTag.js:114 Uncaught Error: Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid. at insertStyleElement (injectStylesIntoStyleTag.js:114:1) at addStyle (injectStylesIntoStyleTag.js:208:1) at modulesToDom (injectStylesIntoStyleTag.js:81:1) at module.exports (injectStylesIntoStyleTag.js:239:1) at Module../common/components/auth/login-button.css (login-button.css?987d:9:17) at __webpack_require__ (bootstrap:24:1) at fn (hot module replacement:61:1) at Module../common/components/auth/login-button.tsx (app-header.tsx:65:3) at __webpack_require__ (bootstrap:24:1) at fn (hot module replacement:61:1) index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <noscript id="jss-inser

Given IV as type String not 16 bytes long - AES decryption in python

So I am fairly new to AES en/decryption and I want to decrypt a message, which was encrypted via AES256 (Rjindael). I was given a key and a IV, both as string. Cyphermode is cbc, If this matters. I use the Crypto Library. key = "some_key" iv = "some_iv" cipher = AES.new(key, AES.MODE_CBC, iv) message = Crypto.Util.Padding.unpad(cipher.decrypt(ct), AES.block_size) This code gives me and Error saying 'IV must be 16 bytes long'. I added this under iv but this did not change anything iv = bytes(iv,'utf-8') What am I missing here? I am sure it is some basic concept which I missed, so I'd be glad, if you could help out source https://stackoverflow.com/questions/71115738/given-iv-as-type-string-not-16-bytes-long-aes-decryption-in-python