python-3.x

PySimpleGUI button event not working in Python code – why?

PySimpleGUI button event not working in Python code – why? Question: Why the button event is not avalible with pysimplegui? This is my Code. import os import threading import PySimpleGUI as gui from rsa_controller import decryptwithPrivatekey, loadPublicKey, loadPrivateKey id = 0 target_id = 0 prikey = None def popout(title): gui.popup(title) def read_keys(): print("Opening key files: …

Total answers: 1

scipy.signal not defined, but works after importing skimage

scipy.signal not defined, but works after importing skimage Question: I would like to use scipy.signal.convolve2d() function from SciPy, but signal is undefined: >>> import scipy … >>> conv = scipy.signal.convolve2d(data, kernel, mode="same") Error: Traceback (most recent call last): File "test.py", line n, in <module> conv = scipy.signal.convolve2d(data, kernel, mode="same") AttributeError: module ‘scipy’ has no attribute …

Total answers: 1

Confused about creating a result matrix for NxN matrix transposition in Python

Confused about creating a result matrix for NxN matrix transposition in Python Question: NxN Matrix transposing gives wrong answers upon making "result" matrix = input matrix Novice programmer here. I am trying to transpose a NxN matrix. Putting the code here to make the problem clear: def flippingMatrix(matrix): result=[[0 for i in range(len(matrix))] for j …

Total answers: 2

How to raise custom exceptions in a FastAPI middleware?

How to raise custom exceptions in a FastAPI middleware? Question: I have a simple FastAPI setup with a custom middleware class inherited from BaseHTTPMiddleware. Inside this middleware class, I need to terminate the execution flow under certain conditions. So, I created a custom exception class named CustomError and raised the exception. from fastapi import FastAPI, …

Total answers: 2

How do I add a space between the Double Quotes and Colon in the key values of the dictionary?

How do I add a space between the Double Quotes and Colon in the key values of the dictionary? Question: The following is my code: import json def value_list(sentence): word_list = sentence.split(" ") total_number_of_words_in_the_sentence = len(word_list) value_list = [] for i in range(0, total_number_of_words_in_the_sentence): count1 = word_list.count(word_list[i]) value_list.append(count1) return value_list def wordlist1(sentence): import json word_list …

Total answers: 1

XPath SyntaxError: invalid predicate with text()

XPath SyntaxError: invalid predicate with text() Question: What am I doing wrong? When using what I believe to be a valid XPath expression in Python, I get a "SyntaxError: invalid predicate" result. My code is: import xml.etree.ElementTree as ET data = ”'<root> <child> <p>aaa</p> <p>bbb</p> </child> </root>”’ root = ET.fromstring(data) p_element = root.findall(".//p[text()=’aaa’]") print(p_element[0].text) Running …

Total answers: 1

applying Singleton to Spotipy throws error

applying Singleton to Spotipy throws error Question: Spotipy’s object needs to be passed a credential kw arg my code: import spotipy class Spoti2(spotipy.Spotify): spoty_obj = None @classmethod def __new__(cls, client_credentials_manager): if cls.spoty_obj is None: cls.spoty_obj = super().__new__(cls) print(‘se creo instancia’) return cls.spoty_obj but i get the error: Spoti2.__new__() got multiple values for argument ‘client_credentials_manager’ however, …

Total answers: 1