All Questions
29
questions
1
vote
1
answer
40
views
Triggering method with change in object property
I have an array of dataframe objects (columns of a larger dataframe) that I am passing into the Dataframe_Builder_Update class. I am able to successfully update the date and associated calculation of ...
0
votes
2
answers
2k
views
TypeError: object of type 'property' has no len()
I have this code of a class that contains a list _offers of custom Offer objects. For this list I created a property to allow access to it:
class OffersManager:
_offers: list[Offer] = []
...
0
votes
1
answer
386
views
How can the following: "axes.yaxis.set_major_formatter(FuncFormatter(f))" work since yaxis should be an attribute of AXIS and not of AXES objects?
Practicing on visualization as a Python newbie I have encountered this conceptual issue that got me thinking,
Infact I managed to change the price format on the y axis of a boxplot , from scientific ...
-1
votes
1
answer
343
views
Python 3.7 Class Property Returns Object
I am trying to create a class with properties. Every time I access the property, no matter how I try, I get <property object at xxx>. I am running version 3.7.8 in Visual Studio Community 2019....
-1
votes
1
answer
360
views
Python: How to: attribute of an instance which depends on flag, which is itself an attribute of that instance / object
Consider the following minimal example for my question:
class MyClass:
a = False
b = 0
if a:
b = 1
MCinst = MyClass()
Here MCinst has two attributes, MCinst.a and MCinst.b with ...
0
votes
2
answers
457
views
Method that can alter multiple properties within an object in Python [duplicate]
I am trying to use a method within an object to selectively change specific properties of that object. I haven't been able to figure out how to get the method to recognize the values that I pass to it ...
0
votes
0
answers
215
views
Python: Property setter using hasattr to provide validation and immutability
I'm using a property to provide validation and self encapsulation for attributes of a class. The attribute should also be immutable. I'm currently have something like this:
def __init__(self, ...
2
votes
2
answers
1k
views
Set default (initial) value for descriptor
Assume we got the following code:
class NonNegative():
def __set_name__(self, owner, name):
self.name = name
def __get__(self, instance, owner):
if instance is None:
...
0
votes
2
answers
364
views
How to have multiple versions of the same object, each with different properties
I'm making a text based version of Skyrim and I'm unable to find a way to make enchantments/smithing bonuses work. I have a class for weapons and a class for armor. I have an object for each weapon ...
0
votes
1
answer
2k
views
How to make Multiply function inside a Class Python
What am I missing here in the code or in function area? any pieces of advice? if anybody knows a very good place to study from it object-oriented programming please tell me and thanks.
class Square():...
0
votes
0
answers
83
views
Accessing Python Dictionary mappings from JSON load()
I am using JSON to parse an object to a Python object. I have an array that looks like this:
arr=['a','b','c']
and the JSON data looks like this:
{"a":"hhh","b":1,"c":"nnnn"}
I load the data ...
3
votes
2
answers
140
views
how do I create a dict with all fields and properties of a python object?
Suppose if I have a class as shown below,
class TestClass(object):
def __init__(self):
self.name = 'Marty'
self.age = 25
self.place = 'CL'
@property
def country(...
5
votes
1
answer
11k
views
Apply `map` over property in python
I'd like to map over a property, so I tried
map(lambda o: cls.prop(o), list_of_objects)
The property is defined in an external library as:
@property
def prop(self):
However, I get a TypeError ...
1
vote
1
answer
52
views
How to I have a default object property and have the option of setting it?
I've been reading about setting object properties, but I was confused and haven't succeeded in attempts.
I want create a new object. i.e. Thissle = yt_video()
Then, if I run Thissle.url I want a ...
0
votes
0
answers
23
views
Iterate & Print over each Method/Attribute of an object
I'm sure this is something simple but can't get to work. I want to iterate over all the attr and methods of a defined variable. However I keep one of 3 errors:
None (returned several times)
... has ...