Skip to content

Tag: python

Inconsistent “OSError: [Errno 22] Invalid argument” error

The add_to_log function defined in the following code is called thousands of times during the execution of a script: It usually works as expected, but once in a while it crashes with: I tested it 3 times, it crashed after 3200, 1700 and 10200 calls. I think I can use a try / except block and give it another t…

Too Much Wait TIme

So I was trying to use a procedure(with a parameter)…I asked the user for inputs and created a validate function to check the inputs and see if they are strings…I checked it but the outputs are taking too long to output. How do I fix this? I tried: But it came out to be: Enter first character(lowe…

Expand bounding boxes in edges of images to square

I have a function designed to expand bounding boxes in images to squares. It works fine for cases where the bounding box appears inside the image, but fails to expand boxes in the edges of images (i.e. when the bounding box is [979, 157, 1080, 261] and the image shape is (1080, 1920, 3)) What can I do make su…

How to iterate over nested list to input missing values

I have two objects, a variable (username), and a list (products) of products and costs All prices are unique to each customer. Similarly, the product set is also unique to each customer, so I cant say take a specific index such as products[0] and it would always be ‘pr1’. I’ve zipped the two…

How can I embed a quote inside an f-string?

I’m currently conducting a PR review and came across this: Nothing particularly wrong with it but I figure it can be improved using f-strings, join() and a list comprehension. However it requires me to embed some quotes in my f-string expression and I can’t figure out how to do it. Here’s a …

How to get route’s name using FastAPI/Starlette?

How can I get the name of a route/endpoint using FastAPI/Starlette? I have access to the Request object and I need this information in one of my middlewares. For example, if I hit services/1, I should then be able to get the abc name. Is this possible in FastAPI? Update 1: Output of request.scope Update 2: Pr…

Different aggregate function based on value of column pandas

I have the following dataframe I would like to add a new column, agg_y, which would be the the max(y) if label==”bottom” and min(y) if label==”top”. I have tried this which gives the correct result I am just looking fora one-liner solution, if possible Answer Your solution in one line …