Questions tagged [python-datamodel]

For questions about various details related to Python data model: built-in types, classes, metaclasses, magic __dunder__ methods, operators, object initialization, attribute lookup, etc. Always remember to use 'python' tag together with this one. Using specific tag like 'operators' or 'metaclass' when appropriate is encouraged.

99 questions
0
votes
1 answer

Is there a way to access the underlying dict from a dict subclass?

I'd like to build a special dict class that has the option to export it's underlying dict as a whole (not just the individual items), i.e. something like this: class CustomDict(dict): def export(self): return ??? # A dict instance I…
gmolau
  • 2,815
  • 1
  • 22
  • 45
0
votes
1 answer

Precreated values in the Python universe

As far as I know (correct me if I am wrong) there are some values created on startup by the Python interpreter. Is there a way of finding out which values these are?
steffen
  • 8,572
  • 11
  • 52
  • 90
0
votes
0 answers

Why does type subclass object?

I am learning the Python data model. I have read this article. In this question @poke answered how the built-in function isinstance works. It explained: >>> isinstance(type, object) #Because type.__base__==object True >>> isinstance(object,…
0
votes
1 answer

How to get parent classes of class in my meta class?

I have the following script: #!/usr/bin/python3 class MyMeta(type): def __new__(mcs, name, bases, dct): print(name + " " + str(bases)) return super(MyMeta, mcs).__new__(mcs, name, bases, dct) class A(metaclass=MyMeta): def…
Denis
  • 3,595
  • 12
  • 52
  • 86
0
votes
4 answers

Querying data based on 3rd level relationship in CakePHP

I have the following relationships set up: A HABTM B B belongsTo C C hasMany B Now, for a given A, I need all C with the B's attached. I can write the SQL queries, but what's the proper CakePHP way? What method do I call on which model, and with…
Icing
-1
votes
1 answer

Create class and represent it without quotation marks

I need to represent my datatype PS without the leading and finishing quotation marks. (so that '+' becomes +) I tried overriding repr but cannot figure out, how to properly do it. My problem: class E: # Expression-Class …
jamesB
  • 291
  • 2
  • 12
-1
votes
1 answer

how do i Determine a Cut-Off or Threshold When Working With Fuzzymatcher in python

Please help on the photo is a screenshot of my output and code as well, how do i use the best_match_score I NEED TO FILTER BY THE RETURNED "PRECISION SCORE" THE COLUMN ONLY COMES AFTER THE MERGE (i.e. JUST RETURN EVERYTHING with 'best_match_score'…
-1
votes
1 answer

A lean interface for making python decorator classes

I've been looking to make an object-oriented setup to make decorator factories. A simple version can be found in this stackoverflow answer. But I'm not totally satisfied with the simplicity of the interface. THe kind of interface I envision would…
thorwhalen
  • 1,920
  • 14
  • 26
-1
votes
1 answer

Class with '__getitem__' has no 'get' method

I realize that naturally a class with no get method has no get method. What would be the best way to add a get method to a class implementing __getitem__ [without boilerplate]? I tried: class Foo(): def __getitem__(self, item): ... …
ThorSummoner
  • 16,657
  • 15
  • 135
  • 147
1 2 3 4 5 6
7