Category "python-3.x"

How do I type hint a method with the type of the enclosing class?

I have the following code in Python 3: class Position: def __init__(self, x: int, y: int): self.x = x self.y = y def __add__(self, oth

Trying to understand this potentially virus encrypted pyw file

Today I realised this .pyw file was added into my startup files. Though I already deleted it, I suspect what it may have initially done to my computer, but it's

How to include JSON and File data together in FastAPI endpoint?

I would like to POST JSON and File data together, as shown in the code below: fastapi.py @router.post('/rate') def users(user_review:schemas.Rate, image123: Upl

slicing with .loc in pandas

I was reading the book - "Python for Data Analysis" and doing code side-by-side on Jupiter notebook. Here is my DataFrame named data : one t

Python, Convert Arbitrary List of Floats to Decimals with Most Precision without Rounding Errors

I'm writing code that has to take a bunch of floats in Python and convert them to decimals without any rounding errors but with as much precision as possible. I

How to filter the elements from nested lists composed of strings

I am trying to access elements from the nested lists. For example, file = [["Name","Age","Medal","Location"],["Jack","31","Gold","China"],["Jim","29","Silver","

How to print data if only matching string found in list?

key_word = ["apple","Apple","Boy","boy"] title1 = "Where the boy" title2 = "The Boy playing cricket" title3 = "hello world" title4 = "I want to buy apple vine

Configurable mapping file python

My company is consuming an API that will give us large JSON objects. The API response info may be in dif fields based on query parameters (it's a 3rd party aggr

Why the local variable problem happens in python

I got this error increment = lambda x : x + 1 def make_repeater(h, n): def f(x): value = x while n > 0 : value = h(value)

Giveaway Bot with buttons discord.py

Hi this is my giveaway bot command, currently, I am using reactions in it but I want to replace it with buttons like someone clicks on the button then participa

Cannot install Atom packages. npm ERR! code E500

I've just installed Atom and I wanted to install some packages. However, I couldn't do it due to this error: Installing “[email protected]” failed.Hide

Intercept specific function invocations using parent/child classes?

I am writing a framework that allows us to intercept certain function invocations so that we can manage them(enforce timeouts and retries, persist return

aiogram.utils.exceptions.NetworkError breaks while loop of telegram bot

There is a telegram bot on aiogram. # ... missing code... async def current_info(message: types.Message, state: FSMContext): current_data = {} while Tr

Add a column based on a condition that iterates over a list

So I have the following dataframe: Person_x Person_y Apple_x Banana_x Orange_x Apple_y Banana_y Orange_y Tomas Sidd

What is the correct OOP way to add functionality to a set of classes deriving from an abstract base class?

Setting My friend told me that in OOP, you generally don't want to modify any abstract base classes in an existing codebase, because that means you have to impl

What is the python equivalent for names() function in R

I have a code in R, where in the data frame "inputdata" there are multiple columns, and we are replacing the word "new" with "old" in the entire data frame: nam

Adding new dataframe colonms using information extracted from the url in the url column, but the url could be missing information

Given: A pandas dataframe that contains a user_url column among other columns. Expectation: New columns added to the original dataframe where the columns are co

Getting `A value is trying to be set on a copy of a slice from a DataFrame.` when setting a column

I know a value should not be set on a view of a pandas dataframe and I'm not doing that but I'm getting this error. I have a function like this: def do_somethin

Pip Install failure with error TLSV1_ALERT_PROTOCOL_VERSION in RHEL 8

I am getting error when installing packages using pip install on RHEL8 version WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=

MetaData Generation Failed while installing PyQt5

I have a similar problem as AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' for PyQt5 5.15.0. Most of the solutions pr