I am trying to code a Python function to insert my CSV file to MongoDB database using MongoClient() but I don’t know how to dynamically code the collection name. Here is my code: If I write my code like above, the collection name will be “file_name” instead of the parameter file_name. Anyone…
Fill a rectangle area with an image
I have a code from OpenCV docs regarding template matching as follows: Right now the rectangle drawn on my image is not filled, I would like to fill the area of the cv2.rectangle with some image. How to achive this? Answer If you are filling the rectangle with the template image, then the dimensions of the te…
Given a folder path in Colab, how can I extract a specific portion of that in python?
For an example, I have my folder path as “/content/data/a/b/c/d/” How can I extract the “b” from this path? Answer If “b” never moves If it does move
Auto-increment number in a text file
I have a text file with some patient information. I want to add a new patient into the file while incrementing the id automatically. How can I check the last id number in the file and increment it based on that? Answer Open the file in r+ so that the file pointer is at the beginning vs at the end
Date comaprison in python attribute error
I have a date stored in a text file in this format “19 May 2021”, I want to compare this date to the today’s date to see if we have reached this date or not (> / <) comparisons. I was instructed to first convert this string date to a date object, I am failing to do so. For overdue_task…
When I try to install the paramiko module in Python 3.5.1, I get an invalid syntax and cannot install it
When I tried to add a module called paramiko to Python 3.5.1 to add ssh communication functionality at the command prompt, I got the following error message and could not install it. For the installation method, I entered the following I hope you can help me with this problem, thank you. Answer As shown in th…
python convert timedelta to meaningful string such as “1 hours”
I want to convert a python timedelta object to an easy to read meaningful string for example: any ideas how to do that? Thanks Answer Actually timedelta class, provides you days, seconds, microseconds property directly. But in order to get “hours” and “minutes” you can do some simple c…
check if subarray is in array of arrays
I’ve got an array of arrays where I store x,y,z coordinates and a measurement at that coordinate like: Now before adding a measurement for a certain coordinate I want to check if there is already a measurement for that coordinate. So I can only keep the maximum val measurement. So the question is: Is [x…
Print values of an array as x coordinates and y coordinates seperately – IndexError: list index out of range
I am trying to plot values of x coordinates and y coordinates of image array seperately step1: 2 image arrays are given of size (10,2) step2: find matching coordinates if they are same or distance between them is lessthan 3 step3: print x coordinates and y coordinates of image1 & image 2 My code: expected…
Defining functions dynamically does not work inside class objects?
In my current project, I am constructing functions dynamically by assembling a string, executing this string, then appending the resulting functions to a list. This works well inside a console, even when looped, but strangely does not work when I attempt to do the same thing inside a class object. Do you know…