I’m trying to prevent SQL injections with code in Python, using library sqlite3. I went accross all websites in existence concerning this issue, but none of them are fixing my problem. This statement is here is executed via an email_in_use(email:str) function, to check if an email does exist in the cred…
Tag: python
How to separate the socketio connection by the path of the URL in my flask chat app
I am trying to build a chat app using Flask-socketio, where clubs can have their members talk to each other. The app differentiates the chats of different clubs using arguments in the URL, as shown in the “/chat/<club_code>” route. However, the socketio connection is updating both chats with…
How to clear a dictionary after return?
I am having issue cleaning dictionaries after return the one. I am using fastAPI and my API GET an Age value then I create a list of ages with 4 values including my received value. I am looking to receive always 4 values only the input age and the other ones, in first execution the code works correctly but if
How to add x offset to LMFIT models
i am trying to use LMFIT to fit a power law model of the form y ~ a (x-x0)^b + d. I used the built in models which exclude the parameter x0: DATA Data Plot: This brings up an error because my data starts at about x = 57000. I was initially offsetting my x-axis by x-57923.24 for all x
Extract address from unstructured table row with BeautifulSoup
I have a HTML document where I want to extract the address but I’m unable to. Here is the HTML document. It contains an address that is not enclosed with brackets, and a beginner like me is not able to extract it without it (e.g. with find() or similar). I would like to extract the address Rose Avenue 3…
Add missing timestamps for each different ID in dataframe
I have two dataframes (simple examples shown below): df1 shows every timestamp I am interested in. df2 shows data sorted by timestamp and ID. What I need to do is add every single timestamp from df1 that is not in df2 for each unique ID and add zero to the value column. This is the outcome I’m intereste…
Numpy: Indexing 3D matrix using 1D array
I’m trying to index this array of shape (3,2,2) with an array of shape (3) containing the y-index of the value I want to get. I tried to make it work with for in statement, but is there an elegant way to do it with numpy? Answer So you want arr[0,0,:], arr[1,1,:], arr[2,1,:]? How about
Execute code whenever the space bar is pressed?
I am making this kind of a game but it isn’t really a game so basically I want this to run every time I hit space but it doesn’t work no matter what I try so I would be really thankful if somebody could have helped me out on this. Answer You need to put the if statement in a
How to extract exact match from list of strings in Python into separate lists
This is an example list of strings I would like to extract XIC(Switch_A) into one list, OTE(Light1) into another list, TON(Motor_timer) into another list and so on. This is the code in Python 3 that I have tried How do I go about extracting OTE(Tag name), XIC(Tag name), XIO(Tag name) into their own lists or g…
python-mysql-connector: I need to speed up the time it takes to update multiple items in mySQL table
I currently have a list of id’s approx. of size 10,000. I need to update all rows in the mySQL table which have an id in the inactive_ids list that you see below. I need to change their active status to ‘No’ which is a column in the mySQL table. I am using mysql.connector python library. Whe…