python-datamodel

Get fully qualified class name of an object in python

For logging purposes I want to retrieve the fully qualified class name of a Python object. (With fully qualified I mean the class name including the package and module name.) I know about x.__class__.__name__, but is there a simple method to get the package and module? ...

Is everything greater than None?

Is there a Python built-in datatype, besides None, for which: >>> not foo > None True where foo is a value of that type? How about Python 3? ...

How to count both sides of many-to-many relationship in Google App Engine

Consider a GAE (python) app that lets users comment on songs. The expected number of users is 1,000,000+. The expected number of songs is 5,000. The app must be able to: Give the number of songs a user has commented on Give the number of users who have commented on a song Counter management must be transactional so that they alway...

Python: Implementing slicing in __getitem__

I am trying to implement slice functionality for a class I am making that creates a vector representation. I have this code so far, which I believe will properly implement the slice but whenever I do a call like v[4] where v is a vector python returns an error about not having enough parameters. So I am trying to figure out how to defin...

How is the 'is' keyword implemented in Python?

... the is keyword that can be used for equality in strings. >>> s = 'str' >>> s is 'str' True >>> s is 'st' False I tried both __is__() and __eq__() but they didn't work. >>> class MyString: ... def __init__(self): ... self.s = 'string' ... def __is__(self, s): ... return self.s == s ... >>> >>> >>> m = MyString() >>> m ...

When where and how can i change the __class__ attr of an object in Python?

I'd like to be able to do: >>> class a(str): ... pass ... >>> b = a() >>> b.__class__ = str Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __class__ assignment: only for heap types ...

What is the easiest way to search through a list of dicts in Python?

My database currently returns a list of dicts: id_list = ({'id': '0c871320cf5111df87da000c29196d3d'}, {'id': '2eeeb9f4cf5111df87da000c29196d3d'}, {'id': '3b982384cf5111df87da000c29196d3d'}, {'id': '3f6f3fcecf5111df87da000c29196d3d'}, {'id': '44762370cf5111df87da000c29196d3d'}, ...

What does this Python code mean?

__author__="Sergio.Tapia" __date__ ="$18-10-2010 12:03:29 PM$" if __name__ == "__main__": print("Hello") print(__author__) Where does it get __main__ and __name__? Thanks for the help ...

Python std methods hierarchy calls documented ?

Hi, just encountered a problem at dict "type" subclassing. I did override __iter__ method and expected it will affect other methods like iterkeys, keys etc. because I believed they call __iter__ method to get values but it seems they are implemented independently and I have to override all of them. Is this a bug or intention they don't...