Re: subclassable types

2013-02-22 Thread Daniel Urban
On Fri, Feb 22, 2013 at 12:00 PM, Christian Heimes wrote: > Am 22.02.2013 10:35, schrieb Wolfgang Maier: >> Also: can you use introspection to find out whether a type is valid as a >> base type? > > I don't think so. For CPython the information is stored in the type's > structure. When type->tp_fl

Re: len() on mutables vs. immutables

2012-10-18 Thread Daniel Urban
On Thu, Oct 18, 2012 at 8:42 PM, Demian Brecht wrote: >> str, bytes, bytearrays, arrays, sets, frozensets, dicts, dictviews, and >> ranges should all return len in O(1) time. That includes the possibility >> of a subtraction as indicated above. > > Awesome. Pretty much what I figured. Of course, I

Re: About a list comprehension to transform an input list

2012-06-08 Thread Daniel Urban
On Fri, Jun 8, 2012 at 6:10 PM, Julio Sergio wrote: > >From a sequence of numbers, I'm trying to get a list that does something to > >even > numbers but leaves untouched the odd ones, say: > > [0,1,2,3,4,...] ==> [100,1,102,3,104,...] > > I know that this can be done with an auxiliary function, a

Re: Recursion error in metaclass

2011-06-11 Thread Daniel Urban
On Sat, Jun 11, 2011 at 21:39, Terry Reedy wrote: > What may not be obvious from the docs is that the metaclass calculation > described in the doc section on class statements is carried out within > type.__new__ (or after a possible patch, called from within that), so that > type calls are really

Re: function annotations in open source projects

2011-03-14 Thread Daniel Urban
> Do you know any open source python3 projects that use function > annotations? I would like to see some real use, so maybe I find them > useful to use in my own project. threecheck uses them for type checking: http://pypi.python.org/pypi/threecheck Daniel -- http://mail.python.org/mailman/list

Re: Init a dictionary with a empty lists

2011-02-05 Thread Daniel Urban
On Sat, Feb 5, 2011 at 15:38, Steven D'Aprano wrote: > On Sat, 05 Feb 2011 14:38:29 +0100, Daniel Urban wrote: > >> On Sat, Feb 5, 2011 at 14:08, Lisa Fritz Barry Griffin >> wrote: >>> Hi there, >>> >>> How can I do this in a one

Re: Init a dictionary with a empty lists

2011-02-05 Thread Daniel Urban
On Sat, Feb 5, 2011 at 14:08, Lisa Fritz Barry Griffin wrote: > Hi there, > > How can I do this in a one liner: > >        maxCountPerPhraseWordLength = {} >        for i in range(1,MAX_PHRASES_LENGTH+1): >            maxCountPerPhraseWordLength[i] = 0 maxCountPerPhraseWordLength = {0 for i in ra

Re: can't use multiprocessing with class factory?

2011-01-28 Thread Daniel Urban
On Fri, Jan 28, 2011 at 20:02, Alan wrote: > Can the below example be fixed to work? > Thanks, > Alan Isaac > > import multiprocessing as mp > > class Test(object): >    pass > > def class_factory(x): >    class ConcreteTest(Test): >        _x = x >    return ConcreteTest > > def f(cls): >    prin

Re: Behaviour-based interface/protocol implementation?

2011-01-28 Thread Daniel Urban
On Fri, Jan 28, 2011 at 11:32, Alan Franzoni wrote: > On Thu, Jan 27, 2011 at 11:41 PM, Daniel Urban wrote: > >> Actually it can. You don't have to modify the object, just check for >> the desired methods/signature/whatever. See for example the >> implement

Re: Behaviour-based interface/protocol implementation?

2011-01-27 Thread Daniel Urban
On Thu, Jan 27, 2011 at 20:05, Alan Franzoni wrote: > On Thu, Jan 27, 2011 at 8:03 PM, Alan Franzoni wrote: >> Yes, __instancecheck__ could be used as an alternative hook with >> respect to maybe_implemented_by(), but there's no such logic for >> signature checking. That's a minor detail, I think

Re: Behaviour-based interface/protocol implementation?

2011-01-26 Thread Daniel Urban
> That's just what I'd like and I suppose can't be currently done with > current ABC, PyProtocols or zope.interface implementations, right? It can. With __instancecheck__ you can override isinstance. It is possible (for example) to write a subclass of abc.ABCMeta, which extends __instancecheck__ t

Re: collections.Set Binary Reflected Operations

2011-01-19 Thread Daniel Urban
On Thu, Jan 20, 2011 at 01:51, Chris Kaynor wrote: > I am implemented a custom set-like type which interacts with some > third-party software when retrieving and mutating the set, and have derived > my custom type off of collections.MutableSet, however I have noticed that > some of the magic metho

Re: How can a function find the function that called it?

2010-12-24 Thread Daniel Urban
On Fri, Dec 24, 2010 at 17:24, kj wrote: > (BTW, I don't understand why inspect doesn't provide something as > basic as the *class* that the method belongs to, whenever applicable. > I imagine there's a good reason for this coyness, but I can't figure > it out.) One function object can "belong to

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-12-12 Thread Daniel Urban
> So far, the only situation I can find where method names necessarily > overlap is for the basics like __init__(), close(), flush(), and > save() where multiple parents need to have their own initialization > and finalization. One other possibility is subclasses of the JSONEncoder class. For exam

Re: decouple copy of a list

2010-12-10 Thread Daniel Urban
b = list(a) or b = a[:] -- http://mail.python.org/mailman/listinfo/python-list

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Daniel Urban
> However, what exactly does ^ do? Bitwise XOR: http://docs.python.org/py3k/reference/expressions.html#binary-bitwise-operations -- http://mail.python.org/mailman/listinfo/python-list

Re: errors and exception

2010-08-16 Thread Daniel Urban
> f = open("myfile.txt") > for line in f: >   print line > f.close()   # This is what the "with" statement guarantees; so now just do > it yourself Not exactly. More like: f = open("myfile.txt") try: for line in f: print line finally: f.close() Daniel -- http://mail.python.org/

Re: how to change a string into dictionary

2010-08-09 Thread Daniel Urban
> a = "{'a':'1','b':'2'}" > how to change a into a dictionary ,says, a = {'a':'1','b':'2'} See also the ast.literal_eval function: http://docs.python.org/py3k/library/ast.html#ast.literal_eval Daniel -- http://mail.python.org/mailman/listinfo/python-list

Re: new to python - trouble calling a function from another function

2010-08-05 Thread Daniel Urban
> I'm building an elevator simulator for a class assignment. I recently ran > into a roadblock and don't know how to fix it. For some reason, in my > checkQueue function below, the call to self.goUp() is never executed. It is > on the last line of code I pasted in. I can put print statements before