Skip to content

Set an optional endpoint parameter dynamically

What is the best way to set an optional endpoint parameter dynamically? Naively, I have tried with activated_on: Optional[date] = Depends(date.today) thinking FastAPI would call the callable, but it doesn’t work. Answer TL;DR Change the callable of your Depends to a helper function, and inject the optio…

validation-remove currency symbol from price

I have this one string, which is actually price, this price value comes with any currency symbol (currency_list), I am trying to remove these currency symbols from price and return only price. Till now I am able to do it for prefix and suffix currency symbol using below code , everything works till here. I ju…

How to read a sequence of files as one file (fileinput lacks read)?

I need to read a sequence of files and fileinput seemed just what was needed but then I realized it lacks a read method. What is the canonical way (if any) to do this? (Explicit catenation will be wasteful.) Is there a known technical or security reason that fileinput does not support read? This related quest…

Why my “Elif” isn’t working in this code?

When i run the code my “Elif” dont print anything at the terminal. The code just continues as if nothing is written inside the “elif” quote Im new to coding and i tried for so much time to correct this error but i just couldn’t :( Answer This is because the range is always empty …

best way to iterate through elements of pandas Series

All of the following seem to be working for iterating through the elements of a pandas Series. I’m sure there’s more ways of doing it. What are the differences and which is the best way? Answer TL;DR Iterating in pandas is an antipattern and can usually be avoided by vectorizing, applying, aggrega…

setting columns in multiindex pandas

I have this pandas df which i imported from a csv: Is it possible for everything on the left to be grouped under fresh and everything on the right of the dates to be under column spoil in multiindex format. Such as, there is one column which contains [apple, banana, orange]. I want to do this because later wh…