object

Class that holds variables and has methods?

Class that holds variables and has methods? Question: I have a class like this: class ErrorMessages(object): """a class that holds all error messages and then presents them to the user)""" messages= [] userStrMessages= "" def newError(self, Error): self.userStrMessages+= Error def __str__(self): if self.messages.count() != 0: i=0 for thing in self.messages: self.userStrMessages += self.messages[i] + "n" …

Total answers: 2

How to filter and print particular json dictionaries in python

How to filter and print particular json dictionaries in python Question: I’m in the process of learning python. I encountered a problem with json that I can’t overcome. I have this dataset from json in python: { "Sophos": { "detected": true, "result": "phishing site" }, "Phishtank": { "detected": false, "result": "clean site" }, "CyberCrime": { …

Total answers: 5

Python multiprocessing: calling methods and passing objects in asynchronous calls

Python multiprocessing: calling methods and passing objects in asynchronous calls Question: I am trying to accomplish two things with apply_async (https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.AsyncResult) call: (i) Call a class method (ii) Pass an object as param I have the following baseline code so far: import multiprocessing as mp class myClass(): def __init__(self, id): self.id = id self.val = …

Total answers: 1

How can I access to the attributes of an object of a class?

How can I access to the attributes of an object of a class? Question: I have the following code: class Animal: def __init__(self, age, name) -> None: self.age = age self.name = name def getAge(self): return self.age def getName(self): return self.name class Animals: def __init__(self, index) -> None: self.index = index self.animalList = None def …

Total answers: 1

When I call two methods, one from the parent class and one from the child class, only the first call returns

When I call two methods, one from the parent class and one from the child class, only the first call returns Question: class Smarthphone(): def __init__(self, tamanho, interface): self.tamanho = tamanho self.interface = interface def print_test(self): return "testing parent class" class MP3Player(Smarthphone): def __init__(self, tamanho, interface, capacidade): super().__init__(tamanho, interface) self.capacidade = capacidade def print_MP3Player(self): return …

Total answers: 1

Transforming Pandas pivot-table to multiple arrays of objects

Transforming Pandas pivot-table to multiple arrays of objects Question: I have a Pandas pivot table; The goal is to pass this to a Django rest framework in the form of multiple arrays which I can easily filter in React JavaScript. pivot: x y z Magazine date M1 2018-01 173 68 10 2018-02 184 55 11 …

Total answers: 2

How to update class attributes with load function

How to update class attributes with load function Question: I have a class in which the method save stores the created object to disk using the pickle package: def save( self, filepath, ): #CHECK ATTRIBUTE VALUES pickle_out = open(filepath+’.pickle’, ‘wb’) pickle.dump(self, pickle_out) pickle_out.close() Similarly, I want to add a load method that loads a pickled …

Total answers: 1

for message in messages: TypeError: 'Messages' object is not iterable

for message in messages: TypeError: 'Messages' object is not iterable Question: Am having issues with looping through an object here is my code from django.contrib.auth import get_user_model import json from asgiref.sync import async_to_sync from channels.generic.websocket import WebsocketConsumer from .models import Messages User = get_user_model() class ChatConsumer(WebsocketConsumer): def fetch_messages(self, data): messages = Messages.last_30_messages() content = { …

Total answers: 1

Python object. How to pass a value to one specific method

Python object. How to pass a value to one specific method Question: I have a Python object that represents a camera dolly that moves along a track. The class can store and report its position along the track. I have three methods: MoveBy – which gets the distance from another object (Movie.yIncrement) MoveTo – which …

Total answers: 1