We have a number of dataclasses representing various results with common ancestor Result. Each result then provides its data using its own subclass of ResultData. But we have trouble to annotate the case properly. We came up with following solution: but it stopped working lately with mypy error ClassVar canno…
Tag: python
turn a multiple line of txt file into a dictionary
I have a multiple line of text like: and I need a way to read the txt file, and turn it into a dictionary like this so i can use and get the result of match that ended in draw is there a way to achieve this? Answer I would suggest to use a .json file, this way: The parsing
I am trying to make a SQL query of Update in python but it is giving error
Error :- mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘:00 WHERE Contact_no = 9827355876’ at line 1 How can I do this to make a single query of SQL ? Answ…
Best way to get element in list
I’m wondering what is the best way to return specific element in list based on specific condition, we can assume that there is always one and only one element that satisfy that condition. Example : The previous snip of code works, but i don’t really like access to result with [0] on the final list…
Longest common substring in a text that is inside a list of strings
I’ve come across a problem that similar to the Longest Common Substring problem but with a modification. It’s as follows: A list of strings lst and a string text are provided. The string may or may not contain substrings that are present in the list. I need the first longest substring of text that…
I am getting an error while i am running a function in pandas dataframe.I am getting invalid syntax for the first line of the function
def revised_price(engine-location,price): if engine-location==front: updated_price== price else: updated_price== 2*price return new_profit df[‘updated_price’] = df.apply(lambda x: revised_price(x[‘engine-location’], x[‘price’]),axis=1) Please find the error that i am gettin…
How to resample a dataframe an include start and end times?
So I am working with tick data and I am attempting to resample the dataframe to minute bars, but when resample is called the time series begins and ends the first instance that a tick exists. How would I resample this data such that the first and last times can be specified to a certain start and end time? Ed…
Django Template Aren’t Loading
I’m trying to load different html files into the base.html and they’re not showing. Any ideas? Answer I think you may be confusing template inheritance with template composition. In template inheritance, you have a base page like base.html: Then, you have a second template shoes.html that extends …
How can I join two tables with different number of rows in Flask SQLAlchemy?
I have two tables I want to join. They possess a one-to-many relationship. One is called FundingSource, and the other is called AllocationSummary. They have a different number of columns and a different number of rows (FundingSource has more of both). I need to query the FundingSource table (Table 1) to get a…
How to loop thorough rows of each column in a table?
I am trying to write a small program to transform a database. It is an SQLite database, and I am using Python. I am experiencing a problem where the query I’m writing doesn’t seem to work properly: For some reason, what’s printed here is just a list on the column name repeated a number of ti…