I have the below code that works fully up until I set x=37. At this point, I receive the error TypeError: ‘NoneType’ object is not subscriptable on the variable t[“vintage”][“wine”][“region”][“country”][“name”]. I have added another varia…
Tag: python
Calculate Input Fields while user is filling data in form – Django Model Form
I have a user form through which I can save data to the database. I want certain fields to be auto calculated while I am filling the the form. For e.g. Net Weight = Gross Weight – Tier Weight and stuff like that. I also want to add RADIO BUTTONS for fields like LOADING, UNLOADING, DEDUCTION, etc. where …
itterate through multiple URLs with BS4 – and store results into a csv-format
hi there i am currently working on a little tiny sraper – and i am putting some pieces together i have an URL which holds record of so called digital hubs: see https://s3platform-legacy.jrc.ec.europa.eu/digital-innovation-hubs-tool/-/dih/1096/view i want to export the 700 regords in (to) a csv-format: t…
Pydantic Checking if list field is unique
Currently, I am trying to create a pydantic model for a pandas dataframe. I would like to check if a column is unique by the following I would now like to run a validation here and have it fail since address is not unique. The following returns what I need but i want to be able to reuse this validator
Python – Returning multiple functions from closures
I’m trying to emulate private variables in Python by using function closures. My idea was to define a factory function that returns multiple getters. In Javascript, I would write the following: Is there any way to do the same in Python(i.e., returning multiple function objects from a closure)? Answer So…
Why am I receiving this error? This date function has worked fine in my overall script until today
I am using this date function in a python script of mine and it has been working for months. Now, as of this morning it is not working. Here is an image of the error that I receive when I try and run the function. I receive the error in script when running date function by itself. date function that
Lower execution time for apache log parser in Python
I have an school assignment where I were tasked with writing a apache log parser in Python. This parser will extract all the IP addresses and all the HTTP Methods using Regex and store these in a nested dictionary. The code can be seen below: This code works (it gives me the expected data for the log files we…
How to make a boolean array by checking if the items in an array is in a list?
I’m trying to find every item in an numpy array arr that’s also in an arbitrary list lst and replace them, but while arr > 0 will generate a boolean array for easy masking, arr in lst only works with all() or any() which isn’t what I need. Example input: array (1, 2, 3, 4, 5), list [2, 4,…
Pass multiple variables from one module to another
I have several modules in the folder “Programm/modules” which are called by another script in “Programm”. One for example looks like this: “calculate.py” this I would like to load into another module “print.py” But I get the error “ModuleNotFoundError: No …
How to delete values in a dict based on the presence of child values
I have a dict that looks like this: How can I iterate over the elements of this dict, and exclude any element that has “‘parent’ : None” and no child element (meaning, no other element in this dict has this one as a parent). Expected output: Answer I think this function can help you To…