Questions tagged [python-object]

102 questions
0
votes
4 answers

Is there a way to override the print method in Python 3.x?

Pretty simple question - I have searched but not found an answer to this question. It might be a bit silly to do this but I was curious if it is possible to hook into the print(*arg, **kwarg) function of python 3.X and override it / add…
0
votes
1 answer

How to ignore duplicate object values from display

I have a test class with 3 attributes, a,b,and c. 3 instances of the class has been created with values set for the attributes appropriately, Its given that 'a' attribute is always unique and when two objects with same 'b' value will always have…
jelat
  • 15
  • 2
0
votes
1 answer

How can I call an attribute of an object using something the user has entered?

''' class python_object: def __init__(self, id, username, password): self.id = id self.username = username self.password = password #object_dict is made by importing JSON objects and looks like this object_dict = {1:…
cringle
  • 13
  • 6
0
votes
0 answers

Print Python class objects with attributes in another python file using user input

Main Python code Class: main.py class Dog(): name = "" location = "" barks = False NotNaughty = False def __init__(self, name, **kwargs): self.name = name class Cat(): name = "" location = "" isQuiet =…
user3710436
  • 243
  • 1
  • 2
  • 8
0
votes
1 answer

Immutable objects with same value and type not referencing same object

I have been reading the Python Data Model. The following text is taken from here: Types affect almost all aspects of object behavior. Even the importance of object identity is affected in some sense: for immutable types, operations that compute…
rawwar
  • 4,834
  • 9
  • 32
  • 57
0
votes
1 answer

Why can't you name an object, which is created in a function, exactly the same as it's class-name in Python?

I'm programing a Black Jack game in a Jupyter notebook and for that I have a "player" and a "dealer" class and also a function (BlackJack()) which basically runs the entire game. def BlackJack(): name = input("What is your name: ") while…
0
votes
0 answers

python object attribute randomly deleting itself

i have a problem with python objects where i am creating and iterating over many objects simultaneously. objects are always created with the correct attributes, but when i iterate over those objects, i check for a certain attribute in the object,…
ibrahim.bond
  • 127
  • 1
  • 3
  • 12
0
votes
0 answers

'LAB' object has no attribute 'audioFilePath'

I have a problem with this code: class LAB: def __int__(self): self.r = sr.Recognizer() self.audioFilePath = 'C:\\Users\\user\\Music\\WAV\\male.wav' def test(self): with sr.AudioFile(self.audioFilePath) as…
0
votes
1 answer

Class inheritance and instantiation - confusion between internal calls to __init__() and __new__() methods

This is a follow-up question to a problem I previously posted that was partially resolved with the answer I received. The scenario is that I have 1 class that is defined at run time, that inherits from a class that is defined based on a type:…
Cracoras
  • 347
  • 3
  • 16
0
votes
1 answer

Changing data types on Pandas DataFrame uploaded from CSV - mainly Object to Datetime

I am working on a data frame uploaded from CSV, I have tried changing the data typed on the CSV file and to save it but it doesn't let me save it for some reason, and therefore when I upload it to Pandas the date and time columns appear as object. I…
user11395824
  • 71
  • 1
  • 7
0
votes
1 answer

How to add a generator to a Sympy Poly object?

I am writing some tests for my sympy code, and naturally I need to compare two sympy matrices. Each matrix contains objects of type Poly as its entries (actually, it contains objects of a class that I created which extends the Poly class, but that…
makansij
  • 9,303
  • 37
  • 105
  • 183
0
votes
0 answers

Why do I get ''staticmethod' object is not callable' when I try to get the method?

I try to give the user the possibility to choose which function to use for a class. Snippet 1 Something like this: class TestFoo(): @staticmethod def foo(x, y): return x * y methodstr2method = {'foo': foo} def…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
0
votes
0 answers

Python Using Multiprocessing for the methods of the same Class

I need some help with multiprocessing module of python. I am using Python3.6.6. My code structure is somewhat like this: class ABC(): def __init__(self): self.HOST = 'hostserver.com' self.TCP_PORT = 0123 self.BUFFER_SIZE…
S.T
  • 3
  • 1
  • 6
0
votes
1 answer

setting imported functions as members in a static dictionary

There is a simple class where I want to store some functions statically in a dictionary using different ways: import os, sys class ClassTest(): testFunc = {} def registerClassFunc(self,funcName): ClassTest.testFunc[funcName] =…
crogg01
  • 2,446
  • 15
  • 35
0
votes
1 answer

Python3 not adding 'self' to class function call

I have this asyncio class in python 3.4: class Type1: def __init__(s,websocket,path,flds,MyId): global TypeOnes s.ws=websocket s.pt=path s.iId=flds s.ID=MyId s.cnt=0 TypeOnes[MyId]=s …