Category "python"

Raising Python exceptions

I am aware of how to raise exceptions and how to catch them, but how do you know when to raise a certain common exception such as KeyError or ValueError? And wh

Import pyqt file: ValueError: source code string cannot contain null bytes

I've generated (pyuic5) ui_mainwindow.py file from .ui file made in Qt Designer: from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): d

The file_date function creates a new file in the current working directory,

import os import datetime def file_date(filename): # Create the file in the current directory ___ timestamp = ___ # Convert the timestamp into a readab

Is it possible to redirect inside a middleware class?

class Middleware: def __init__(self, app): self.app = app def __call__(self, environ, start_response): request = Request(environ)

R not changing Plotly colorscales for Contour plots

Okay, so I am using a generic data set to troubleshoot this problem. Here is the code I am entering into R: library(plotly) fig <- plot_ly( type = 'cont

Setting background on Qtableview using a function

IU have a Qt window with a button and a QTableView which loads some data from a pandas dataframe using the QAbstractTableModel. I would like to set the backgrou

Printing a large list in multiple lines

Is there a good way to print a large list in multiple lines? Assume that a list has 10000 elements and by writing that to a file it goes all in a single line wh

Move files to a network folder

Could you tell me please, how to correctly specify the path to the network folder from the Linux operating system in the code? The network folder is accessible

Is Scrapy Asychronous by Default?

I recently ran a spider in my project but I feel like scrapy it is waiting until one page is finished to move on the other one. if I am correct in scrapy's natu

Keep IPython markdown in jupyter notebook after closing it

In jupyter notebook, I am calling a function of a library that does IPython.display.display(IPython.display.Markdown(...)) (see How to programmatically generate

How do I update value in a nested dictionary given a path

I have a nested dictionary nested_dictionary = { "a": { "1": 1, "2": 2, "3": 3 }, "b": { "4": 4, "5": 5, "6": {"x": 10, "xi": 11, "xii": 13}} } I a

Duplicate layers when reusing pytorch model

I am trying to reuse some of the resnet layers for a custom architecture and ran into a issue I can't figure out. Here is a simplified example; when I run: imp

Chrome Devtools Network Selenium python

I am making a code with Selenium in Python and collecting data on a website, and I have noticed that in Chrome's Devtools specifically in the "Network" section

pip install -r requirements.txt not installing libraries in vs code virtual environement

I have created virtual environment in VS code. When i am doing the command pip install -r requirements.txt. Still the vs code says no such module found. Howeve

Querying deeply nested and complex JSON data with multiple levels

I am struggling to break down the method required to extract data from deeply nested complex JSON data. I have the following code to obtain the JSON. import req

"No Operation named [input] in the Graph" when using in a java programm a model from hub.KerasLayer with python and tensorflow 2.1.0

I trained a mobilnet_v2 tensorflow model using tf 2.1.0 and hub.KerasLayer with python and exported it in pb format with tf.keras.models.save_model. I loaded it

Decouple dictionary that contains a list as a value for a particular key

Let's say I have a dict in Python that follows this structure: dict_a = {"a": [1,2,3]} I want to produce an output to 'decouple' dict_a in a list of 3 separate

Python Convert YYYYMMDD string to YYYY-MM-DD string Without Using Datetime

How can I convert a string such as: '20190501' To a string such as: '2019-05-01' Without first converting to datetime, for example: from datetime import

How to convert symmetric matrix to adjacency table

How could I convert symmetric matrix: A B C D A 1 2 3 4 B 2 1 2 3 C 3 2 1 2 D 4 3 2 1 into adjacency matrix?: A A 1 A B 2 A C 3 A D 4 B A 3 B B 1 B C 2 B D

Write data in unknown encoding

Is it possible write data to a file in an unknown encoding? I cannot decode email headers, for example message-id, because if I use handler ignore or a replace