Re: Two Classes In Two Files

2006-08-09 Thread Pedro Werneck
Java way... if you don't want to do it, put both classes in the same file. -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: __contains__ vs. __getitem__

2006-08-09 Thread Pedro Werneck
with a different behavior. It's better for you to override __contains__() too. -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: singleton decorator

2006-08-09 Thread Pedro Werneck
tom _init method for each one of them. You can use the subclass __new__, but that's definitely 'unpythonic'. -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Class attributes, instances and metaclass __getattribute__

2006-08-08 Thread Pedro Werneck
easonable thing to do, exactly for what you mentioned on your code... someone could easily break a lot of stuff doing it the wrong way, instead if not using __dict__. I mailed the list because someone else thought it might be a bug and I was in doubt... now it's clear it was the right thing to do. Regards, -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Class attributes, instances and metaclass __getattribute__

2006-08-08 Thread Pedro Werneck
;>> class C(object): ... __metaclass__ = M ... >>> C.y = 'bar' >>> C.x 'foo' >>> C.y 'bar' >>> o = C() >>> o.x ... AttributeError: 'C' object has no attribute 'x' >>> o.y 'bar' >>> So... both 'x' and 'y' are class attributes, but 'x' is a virtual attribute implemented with M.__getattr__. From the instance I have access to 'y' but not to 'x'. Regards, -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: singleton decorator

2006-08-07 Thread Pedro Werneck
>>> x is y True But __init__ will be called once for each time you call A, even if it's always the same instance returned. If this is a problem, you'll need another method to use for initialization and call it only once. -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Class attributes, instances and metaclass __getattribute__

2006-08-07 Thread Pedro Werneck
oid some problems with method and descriptors creation, since someone using metaclasses and custom __getattribute__ at the same time is asking for trouble, but... I googled for it and tried to find something on the list but, nothing. From the source it seems like a generic wrapper is used. What's the real case here ? Regards, -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrapping classes

2005-09-23 Thread Pedro Werneck
27;initialized') >except AttributeError: # should raise > print 'not initialized' >else: > raise >try: > a.initialized #every look up would do ,even a print >except AttributeError: > raise >else: > print 'initialized' > > > Have fun Paolino > > > > > > ___ > Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB > http://mail.yahoo.it > -- > http://mail.python.org/mailman/listinfo/python-list -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Character Sequence Generation

2005-09-22 Thread Pedro Werneck
;n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] >>> [chr(x) for x in xrange(ord('d'), ord('p') + 1)] ['d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'] >>> [chr(x) for x in xrange(ord('A'), ord('Z') + 1)] ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] etc... -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible bug in "metaclass resolution order" ?

2005-09-19 Thread Pedro Werneck
is really just a documentation problem. Check the comments on the bug report here: http://sourceforge.net/tracker/index.php?func=detail&aid=1294232&group_id=5470&atid=105470 -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible bug in "metaclass resolution order" ?

2005-09-18 Thread Pedro Werneck
taclass I set explicitly. I will change the bug report and add some of the suggested documentation. Thanks -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible bug in "metaclass resolution order" ?

2005-09-18 Thread Pedro Werneck
and "explicit is better than implicit". If it's just a documentation issue, the first rule in search order is much more complex than documented. If I am completely wrong in all of this, maybe it's better stop wasting our time. :) Thank you -- Pedro Werneck http://sourceforge.net/tracker/index.php?func=detail&aid=1294232&group_id=5470&atid=105470 -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible bug in "metaclass resolution order" ?

2005-09-18 Thread Pedro Werneck
must be a (non-strict) subclass of the metaclasses of all its bases >>> class C(B): __metaclass__ = M_A ... >>> C.__metaclass__ >>> C.__class__ > You are free to post the bug report and look at the opinions of the > developers. I posted a few hours ago. Thank you. -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible bug in "metaclass resolution order" ?

2005-09-17 Thread Pedro Werneck
.net/tracker/index.php?func=detail&aid=1294232&group_id=5470&atid=105470 -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible bug in "metaclass resolution order" ?

2005-09-17 Thread Pedro Werneck
class conflict error. But with M_A, the error is ignored, probably because PyType_IsSubtype is returning 1 for M_A being a subtype of M_B and the winner and metatype are exchanged later, so we end with M_B as C's real type. > I suggest you to file a documentation bug. Unfortunately the basic > d

Re: Possible bug in "metaclass resolution order" ?

2005-09-17 Thread Pedro Werneck
7:47) [GCC 3.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class M_A(type): pass ... >>> class A: __metaclass__ = M_A ... >>> class B(A): __metaclass__ = type ... >>> B.__class__ >>> B.__metaclass__ Regards, -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Possible bug in "metaclass resolution order" ?

2005-09-16 Thread Pedro Werneck
_class__ to M_B! >>> class C(B): __metaclass__ = type ... >>> C.__metaclass__ >>> C.__class__ >>> type(C) Since the explicit __metaclass__ attribute has priority over parent classes, a case like this is an error and should raise an exception like the metaclass conflict, right ? Regards, -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Supporting << and >> operators in C extension type

2005-07-27 Thread Pedro Werneck
aryfunc)Pin_and, /*nb_and*/ (binaryfunc)Pin_xor, /*nb_xor*/ (binaryfunc)Pin_or, /*nb_or*/ 0, /*nb_coerce*/ ... }; Thanks for any help... -- Pedro Werneck -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble converting hex to decimal?

2005-02-05 Thread Pedro Werneck
Hi The problem is that '\x00' is a escape sequence... Try something like this: >>> x = '\x00' >>> int(repr(x)[3:-1], 16) 0 >>> x = '\x15' >>> int(repr(x)[3:-1], 16) 21 >>> On Sat, 05 Feb 2005 06:51:32 -0700 Earl Eiland <[EMAIL PROTECTED]> wrote: > I'm trying to process the IP packet lengt

Re: is this sort method the same as the one in python 2.4

2005-01-30 Thread Pedro Werneck
What about this ? # if sys.version_info >= (2,4): def sorted(iterable, *args, **kwds): seq = list(iterable) seq.sort(*args, **kwds) return seq # It worked against the TestSorted in lib/test/test_builtins.py On Sun, 30 Jan 2005 08:30:17 +0100 "Fredrik Lundh" <[EM

Re: how do i create such a thing?

2005-01-30 Thread Pedro Werneck
Hi, If you need direct access to some atribute, use object.__getattribute__. >>> class DefaultAttr(object): ... def __init__(self, default): ... self.default = default ... def __getattribute__(self, name): ... try: ... value = object.__getattribute__(self, na

Re: type() takes one or *three* arguments!?

2005-01-30 Thread Pedro Werneck
Hi, Up to Python 2.2, type() was just a function to return an object type. >From 2.2 on, type have this behavior when called with only one argument and is used to create a new type when called with 3 arguments. >From http://www.python.org/2.2/descrintro.html : "The signature of type() requires

Re: tkinter socket client ?

2005-01-27 Thread Pedro Werneck
On Tue, 25 Jan 2005 13:44:32 + Martin Franklin <[EMAIL PROTECTED]> wrote: > > thanks for this info - I had to abandon the createfilehandler() method > > as it is not supported in windows and the GUI "might" be used there at > > some time ... Take a look here: http://www.pythonbrasil.com.br/m

Re: Tuple slices

2005-01-24 Thread Pedro Werneck
On Mon, 24 Jan 2005 18:45:46 +0100 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > > Why does slicing a tuple returns a new tuple instead of a view of > > the existing one, given that tuples are immutable ? > > really? Well... seems like this case (slicing the whole tuple

Re: Tuple slices

2005-01-24 Thread Pedro Werneck
On Mon, 24 Jan 2005 18:45:46 +0100 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > > Why does slicing a tuple returns a new tuple instead of a view of > > the existing one, given that tuples are immutable ? > > really? Well... seems like this case is optimized to return th

Re: TCP server

2005-01-24 Thread Pedro Werneck
A quick example for you: ### import SocketServer class EchoRequestHandler(SocketServer.BaseRequestHandler): def setup(self): print self.client_address, 'connected!' self.request.send('hi ' + str(self.client_address) + '\n') def handle(self): while 1:

Re: Asynchronous event handling...?

2005-01-24 Thread Pedro Werneck
Hi, Maybe something like this... from Tkinter import * import itertools class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.stop = Button(self,text='Emerge

Re: TypeError error on tkinter.createfilehandler dummy example

2005-01-21 Thread Pedro Werneck
can send it to you in pvt, if you want. Pedro Werneck On Fri, 21 Jan 2005 10:27:20 +0100 David <[EMAIL PROTECTED]> wrote: > Hi, > > I'm getting the following error: > > > Traceback (most recent call last): > File "..\kk.py", line 37,