Skip to content

Tag: python

Read out file and convert certain line into a correct form

I have a problem. I am reading in a file. This file contains abbreviations. However, I only want to read the abbreviations. This also works. However, not in the desired format as expected, I would like to save the abbreviations cleanly per line (see below for the desired output). The problem is that I’m…

Comparing if an element in a dictionary is greater than a variable

I am new to Python and have just recently learnt what dictionaries are and was experimenting with some code. I am trying to make it compare if the random_number is greater than the elements in the list scores it, will print out your grade. Since I’m new to coding and honestly suck I need some help Answe…

object data editting form

I’m making django app which allow me to study. It has multiple tests with multiple question each. Every question has one correct answer. I’m trying to make form which allow me to edit answer If I made mistake in passing correct answer during making question. That’s what I have already made: …

Adding string to a string before some certain characters?

I want to add this string the substring above, before every ‘(‘ character. So that it would be look like this below. myString = ‘rgb(247, 246, 244), rgb(13, 23, 24), rgb(85, 101, 100)’ Answer Try using the .replace() method, ie myString.replace(“(“, “rgb(“) this…

FastAPI swagger does not render because of custom Middleware?

So I have a custom middleware like this: Its objective is to add some meta_data fields to every response from all endpoints of my FastAPI app. However, when I served my app using uvicorn, and launched the swagger URL, here is what I see: With a lot of debugging, I found that this error was due to the custom m…

Python code to read a csv file and create a master csv file

I have a folder let’s say as ‘input_Folder’ which has a list of CSV files with data. I’m trying to write a Python code which reads this list of CSV files from the input_folder and creates a master CSV file with two columns. The columns in the master CSV files are ‘Scenario’…

Send WhatsApp message every 24 hours

I want to send a WhatsApp message every 24 hours automatically using python, with the pywhatkit library. Here is the code I got so far: Send every 24 hours adaptation: I would have to keep my PC on 24/7 for this to work. Is there any better way of doing it? Answer