python-3.x

Django ForeignKey("x") field must be a "x" instance on update

Django ForeignKey("x") field must be a "x" instance on update Question: Django version 4.2.9 I try to fix this : Cannot assign "(‘customer’,)": "Project.customer" must be a "Customer" instance. I have 2 classes, Project and Customer. class Customer(models.Model): customer_name = models.CharField(max_length=50) string = models.CharField(max_length=50) def __str__(self): return f"{self.customer_name}" class Project(models.Model): project_name = models.TextField() project_code = …

Total answers: 1

How, in Python 3, can I have a client open a socket to a server, send 1 line of JSON-encoded data, read 1 line JSON-encoded data back, and continue?

How, in Python 3, can I have a client open a socket to a server, send 1 line of JSON-encoded data, read 1 line JSON-encoded data back, and continue? Question: I have the following code for a server listening on a port: def handle_oracle_query(self, sock, address): sockIn = sock.makefile(‘rb’) sockOut = sock.makefile(‘wb’) line = sockIn.readline() …

Total answers: 2

Generating xml ouput file by using python

Generating xml ouput file by using python Question: My input data is present in csv file and need to generate XML output file based on data available in input file. I am trying to implement this requirement with python. I have tried the below code but not getting required output. Input Data(Input.csv file): CustID,CardNo A00001,C000000001 …

Total answers: 1

Problems with reciprocal of an dictionary

Problems with reciprocal of an dictionary Question: given dict: weights = {"A":16, "B": 3, "C": 5) I want to have the reciprocal of the values. Output: weights_dict_reci = {"A":0,0625, "B": 0,3333333, "C": 0,2) So far I tried: weights_dict_reci = {value: 1 / weights_dict[value] for value in weights_dict} and for key in weights_dict: weights_dict[key] = 1 …

Total answers: 2

Making threads in a pool notice changes to global variables

Making threads in a pool notice changes to global variables Question: I’m running into an interesting circumstance with pools which I don’t fully understand. I was aware that if you edit any variable or object from a thread, changes will not be applied to the main thread and only exist in the isolated reality of …

Total answers: 1

Why does adding the decorator @lru_cache(from functools) break this function?

Why does adding the decorator @lru_cache(from functools) break this function? Question: The function is a part of the solution to the following problem: "Find all valid combinations of k numbers that sum up to n such that the following conditions are true: Only numbers 1 through 9 are used. Each number is used at most …

Total answers: 3

bottle / gunicorn not responding to SIGTERM after ANY request

bottle / gunicorn not responding to SIGTERM after ANY request Question: I have used bottle for a long time and never run into this before, but recently I started a new project and encountered some strange behaviour that I just can not track down at all. If I start a bottle instance in my script, …

Total answers: 1

I am trying to import views.py to urls.py using from . import views but I keep getting an import error

I am trying to import views.py to urls.py using from . import views but I keep getting an import error Question: from django.contrib import admin from django.urls import path from . import views urlpatterns = [ path(‘admin/’, admin.site.urls), path("", views.home), path("predict/", views.predict), path("predict/result", views.result) the traceback is File "C:UsersuserPycharmProjectsDiabetes PredictionDiabetes_PredictionDiabetes_Predictionurls.py", line 19, in from . …

Total answers: 2