Skip to content

Tag: python

Return all extra passed to pydantic model

I’m trying to get a list of all extra fields not defined in the schema. I saw solution posted here but it ignores any nested models. Optimal solution would create a variable in the Pydantic model with extras that I could access after new object with passed data is created but not sure if this is even po…

extract hash digits from string

How can I extract only the hash digits in the quotations in various strings such as: I need to extract the digits and insert into a table using this script: So in the above example if the strings before the ‘=’ changes due to different hashes then I won’t be able to be consistent with my pie…

Django Standalone Script in Django 4.1

I am trying to run a standalone script in django 4.1. I have the setup as suggested in this post at the top of my file: Django Standalone Script However, on the 4th line, I get the following error: ModuleNotFoundError: No module named ‘sport_api’ This is my INSTALLED_APPS in settings.py How do I g…

Combine two lists and sort them

Lets say I have two lists. I want to append list2 into list1 and then sort and add a new element at a specific index. I keep getting an error message saying: TypeError: ‘<‘ not supported between instances of ‘list’ and ‘int’ This is what I have tried: Answer Use sorted()…

Save doc file as pdf file using python

I want to save a doc file as pdf using python, I tried so many solution but I couldn’t find the right one. This is my code, I tried to make the output file as a pdf file but it didn’t open. Any help is highly appreciated : Answer There is a Python package called docx2pdf. You can use it

Python Selenium error: Unable to locate the Element by Name:

I am trying to automatically login to the website https://opensource-demo.orangehrmlive.com/web/index.php/auth/login using selenium By it gives an error selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {“method”:”css selector”,&#822…

Django – Create model with fields derivable from other model

I have 2 Django models representing the coin domain. The Coin has some properties and the trading Pair is based on those properties. Let’s add a couple of Coin instances: and one Pair: As you can see, code and name in the Pair model can be derived from code and name in the Coin model. To put it simple: …