Re: Wrapping classes

2005-09-23 Thread Paolino
Paolino wrote: > class NotInitializedObjects(type): > def __init__(cls,*_): > realInit=cls.__init__ > def __newInit__(self,*pos,**key): > def _init(): > realInit(self,*pos,**key) > self._init=_init > cls.__init__=__newInit__ > def

Re: Wrapping classes

2005-09-23 Thread Paolino
or: # 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

Re: Add lists to class?

2005-09-02 Thread Paolino
general, you probably want a dictionary instead of attributes: > > >>>>class C(dict): > > ... def __init__(self, l): > ... for i in l: > ...self[i] = [] > ... > >>>>c = C(['a', 'b', 'c']) >>>>c[&

Re: algorithm for non-dimensionalization

2005-08-26 Thread Paolino
,x4]=[0,0,0] (looking for adimensionals) So you are looking for an eigenvector formed by only integers. Ciao Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get a unique id for bound methods?

2005-08-19 Thread Paolino
odId(c.meth2) I think this is giving what you expected. Regards Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list

Re: dict duplicity

2005-08-18 Thread Paolino
; I'm not sure I got your question but having the same hash(key) is not having the same key for a dict. >>> {-1:0,-2:0} {-2: 0, -1: 0} >>> hash(-1)!=hash(-2) False A key lookup in a dict involve real keys comparisons via '==' among the k

An observer pattern application.

2005-08-18 Thread Paolino
to write a decorator for automatize the 'super' call,but I failed. Next solution is implementing the observer pattern on methods call. I'm pretty sure there are bugs and ideas to be corrected in the next code,any help and comment appr

Re: Library vs Framework (was Dr. Dobb's Python-URL!)

2005-08-16 Thread Paolino
set of highly coupled interfaces useful for humans to describe a task. Ciao Paolino -- http://mail.python.org/mailman/listinfo/python-list

A (unpythonic) pythonable mixin recipe.

2005-08-16 Thread Paolino
L(list): __reinit__=lambda self,other:list.__init__(self,other) l=L([1,2,3]) l=Mixin(l) l.mixinMethod() Regards Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://ma

Re: catching all exceptions

2005-08-13 Thread Paolino
"some error occurred: ", str(e) > > > The not-so-simple case: Handling all other exceptions: > > # nice-to-have: > try: > something() > except *, e: > print "some error occurred: ", type(e), str(e)

Re: Bug on Python2.3.4 [FreeBSD]?

2005-08-12 Thread paolino
Uwe Mayer wrote: > > > Hi, > > AFAICT there seems to be a bug on FreeBSD's Python 2.3.4 open function. The > documentation states: > > >>Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' >>truncates the file). Append 'b' to the mode to open the file in binary >>mode, on syst

Re: simpli int/str problem

2005-08-12 Thread Paolino
use database only accept int in `BH ` > thanks. Try use: SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('%s,%d)"%(dict['str_name'],dict['int_name']) Paolino ___ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list

Re: __getattribute__ for class object

2005-08-12 Thread Paolino
f __getattribute__(klass,attr): value=type.__getattribute__(klass,attr) print attr,'==',value return value class Foo(object): __metaclass__=Meta a=2 Foo.a Paolino -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Adding Functionality to a Class by metaclass(not by inherit)

2005-08-12 Thread Paolino
Dont' know where are you going with that but if what you need is cancelling some attributes when inheriting then probably this is a cleaner approach: class Meta(type): def __init__(cls, name, bases, dic): def attributeError(*_): raise AttributeError for base in bases:

Re: help in algorithm

2005-08-11 Thread Paolino
Bengt Richter wrote: > On Wed, 10 Aug 2005 16:51:55 +0200, Paolino <[EMAIL PROTECTED]> wrote: > > >>I have a self organizing net which aim is clustering words. >>Let's think the clustering is about their 2-grams set. >>Words then are instances of this class

Re: set of sets

2005-08-11 Thread Paolino
Matteo Dell'Amico wrote: > Paolino wrote: > >>I thought rewriting __hash__ should be enough to avoid mutables problem >>but: >> >>class H(set): >> def __hash__(self) >>return id(self) >> >>s=H() >> >>f=set() >> >

set of sets

2005-08-11 Thread Paolino
I thought rewriting __hash__ should be enough to avoid mutables problem but: class H(set): def __hash__(self) return id(self) s=H() f=set() f.add(s) f.remove(s) the add succeeds the remove fails eventually not calling hash(s). Thanks for help Paolino

help in algorithm

2005-08-10 Thread Paolino
om those words. Aka:sum([medium-word for word in words]) Thanks for ideas, Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is this?

2005-08-10 Thread Paolino
Paolino wrote: > Jiri Barton wrote: > >>Hi everyone, >> >>I have a problem with initialization. >> >> >>>>>a, b = [[]]*2 >>>>>a.append(1) >>>>>b >> >>[1] >> >>Why is this? Why does n

Re: Why is this?

2005-08-10 Thread Paolino
gt;>> a==b True > > And, just to add to my confusion: > > >>>>[[]]*2 > > [[], []] > >>>>[[], []] == [[]]*2 > > True This confuses me also,looks like empty lists share same object. Paolino __

Re: namespaces

2005-08-10 Thread Paolino
e tuple ambiguity as with 'somestr' % x > > something analogous to += on immutables would have to be done for builtin > objects I suppose. This is a little hard for me.Has it something to do with extensions also? Regards Paolino __

Re: namespaces

2005-08-10 Thread Paolino
) sys.modules[moduleName]=self def desc(self): pass Free(__name__) #'no errors' but 'desc' is not defined in this namespace. Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list

Re: namespaces

2005-08-09 Thread Paolino
Peter Otten wrote: > Paolino wrote: > > >>Why descriptor mechanism doesn't apply to modules? > > > Because modules are instances of the module class and the descriptor has to > be defined in the class in order to work with the instance. E. g.: > >

namespaces

2005-08-09 Thread Paolino
'm' in mod.__dict__ # this is said to be the key for descriptors # to be called mod.m # doesn't work Thanks Paolino ___ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?)

2005-08-08 Thread Paolino
an almost perfect surface layer. But this is not enough.It needs to be strong and elegant in the insides to survive.More, isn't the "Namespaces do more of them" a Python Zen Law ? Thanks again for putting things in a saner and more open way then I did. Regards Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope'or 'module' better?)

2005-08-06 Thread Paolino
Terry Reedy wrote: > "Paolino" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>[EMAIL PROTECTED] wrote: >>I don't think the global keyword is useful actually. >>What's so special in a module nemespace to be priviledged lik

Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)

2005-08-06 Thread Paolino
Peter Hansen wrote: > Paolino wrote: > >>[EMAIL PROTECTED] wrote: >>def enclosing(): >> var=[] >> var[0]=2 >> def enclosed(): >>var[0]=4 >>which is like saying python is not working >> >>It's ok to mark non locals,but why v

Re: Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)

2005-08-06 Thread Paolino
't point to its namespace and every namespace to its namespace? Unpythonic ? Illogicities to my eyes or at least non-linerities that makes 'global' an interesting strangeness to talk about. And that namespaces should start being easy sooner or later. Regards Paolino

Re: doctest bug with nested triple quotes

2005-08-01 Thread Paolino
file is different. > python -c "print open('x.py').read().encode('base64')" IiIiCmR1bW15ID0gJycnCgpzb21ldGhpbmcKaGVyZQonJycKIiIiCmltcG9ydCBkb2N0ZXN0OyBk b2N0ZXN0LnRlc3Rtb2QoKQo= Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list

Re: namespaces

2005-08-01 Thread Paolino
Paolino wrote: > Now this is the non polluting version : > > class translate: >import string >all=string.maketrans('','') >badcars=all.translate(all,string.letters+string.digits) >@staticmethod >def __call__(text,ta

Re: namespaces

2005-08-01 Thread Paolino
Paul Rubin wrote: > Paolino <[EMAIL PROTECTED]> writes: > >>What I'm needing as a global (in globals() or at the module level or >>in the module namespace) is 'translate'.The rest of bindings >>(all,badcars and table) is something which is 'poll

Re: namespaces

2005-08-01 Thread Paolino
George Sakkis wrote: > Paolino wrote: > > >>>>Even worse I get with methods and function namespaces. >>> >>>What is "even worse" about them? >>> >> >>For my thinking, worse is to understand how they derive their pattern >&

Re: namespaces

2005-08-01 Thread Paolino
Bengt Richter wrote: > Ok, to make the statement execute, execute function: > > >>> function() > >>> a=function.foo > >>> a > 'something' > >>> vars(function) > {'foo': 'something'} > Yep too stupid I've been :) Thanks __

Re: namespaces

2005-07-31 Thread Paolino
t bindings in the end. The second point also shows my perplexities about functions namespace: def function(): function.foo='something' a=function.foo Traceback (most recent call last): File "", line 1, in ? AttributeError: 'f

Re: namespaces

2005-07-31 Thread Paolino
eric namespaces. Methods seems not to have a writeble one,while functions as George and Rob remembered have one which is not read only.Why? (Also my aim is to learn from postings not to show others' implementations are better or worse in t

Re: namespaces

2005-07-31 Thread Paolino
Steven D'Aprano wrote: > def translate(text): > import string > all=string.maketrans('','') > badcars=all.translate(all,string.letters+string.digits) > table=string.maketrans(badcars,'_'*len(badcars)) > return text.translate(table) > > No pollution. And no efficience.Recalcul

Re: namespaces

2005-07-31 Thread Paolino
Robert Kern wrote: > Paolino wrote: > >>While it's not so bad we can bind names in the module namespace, (ex >>writing scripts ?) ,writing modules is someway bound to not polluting >>that namespace (really IMO). > > > I'm afraid that I can't pa

namespaces

2005-07-31 Thread Paolino
ace: __metaclass__=namespaceMeta class ns(namespace): def gulp(*args):pass This solution makes me think the keyword 'namespace' is missing: namespace ns: foo='something' def gulp(*args): pass Solutions and comments appreciated. Regards Paolino

Re: A replacement for lambda

2005-07-30 Thread Paolino
why (x**2 with(x))<(x**3 with(x)) is not taken in consideration? If 'with' must be there (and substitue 'lambda:') then at least the syntax is clear.IMO Ruby syntax is also clear. ___ Yahoo! Mail: gratis 1GB per i messaggi e al

Re: Ten Essential Development Practices

2005-07-29 Thread Paolino
ame code. -Deciding the interface and writing docs before coding can be bad for experimental coding. -Logic optimization can influence interfaces. -Time optimization is a leverage to get paid in open source software.Never think about that for free. Paolino _

Re: why functions in modules need 'global foo' for integer foo but not dictionary foo?

2005-07-28 Thread Paolino
Robert Kern wrote: > [EMAIL PROTECTED] wrote: > >>At top of a module I have an integer like so... >> >>foo = 4 >> >>In a function in that module I know I need to do 'global foo' to get at >>the value 4. >>... > > > I presume you are trying code like the following: > > foo = 4 > bar = {} > > d

Re: Determine if object is a Bound or Unbound method

2005-07-28 Thread Paolino
Farshid Lashkari wrote: > Hi, > > I have an object and I want to check if it is a bound or unbound method, > or neither. I tried using the types module, but it seems as though > types.UnboundMethodType and types.MethodType are equal. How else can I > determine this? BTW, I'm using Python 2.3 >

Re: Advanced concurrancy

2005-07-28 Thread Paolino
or in twisted.internet.defer is the robust way for that. It blows up python readability in contrast,but once you got them and made your library I think they are also usable. I do believe, without deferreds in the core ,python will have bad times surviving the net, but that's really an opinion. Have fun, Paolino -- http://mail.python.org/mailman/listinfo/python-list

Mailing list question

2005-07-28 Thread Paolino
Puzzling. I have subscribed this list with an address int the gmail.com domain, and I receive your postings there,but it seems I can send messages with THIS address ,and I don't receive my messages sent with the gmail account. I don't receive any "python.org mailing list memberships reminder" on

Re: can list comprehensions replace map?

2005-07-27 Thread Paolino
se 'zip' because I'll lose >>>info from x. How do I do this as a list comprehension? (Or, >>>more generally, what is the best way to do this without 'map'?) > > > [Paolino] > >>Probably zip should change behaviour,and cover that

Re: Wrapping a class set method

2005-07-27 Thread Paolino
snoe wrote: > I have a suspicion that there's an easier way to do this than > explicitly adding a Project.pickleme() call to the beginning of all of > my set/add methods. > So is there a way to wrap methods for this type of functionality or is > there another way of doing this, maybe without usi

Re: Wrapping a class set method

2005-07-27 Thread Paolino
snoe wrote: > I have a suspicion that there's an easier way to do this than > explicitly adding a Project.pickleme() call to the beginning of all of > my set/add methods. > So is there a way to wrap methods for this type of functionality or is > there another way of doing this, maybe without usi

Re: can list comprehensions replace map?

2005-07-27 Thread Paolino
David Isaac wrote: > Newbie question: > > I have been generally open to the proposal that list comprehensions > should replace 'map', but I ran into a need for something like > map(None,x,y) > when len(x)>len(y). I cannot it seems use 'zip' because I'll lose > info from x. How do I do this as a

Re: [Beginner] Calling a function by its name in a string

2005-07-27 Thread Paolino
Tito wrote: > Hi all: > > Is there a metalanguage capability in Python (I know there are many) to > call a function having its name in a string? > > Something like: > __call__("foo") > > instead of: > foo() > > Regards, > Tito eval('foo()') should do, but it's said a bad practice ;) -- http:/

Re: any thing to do???

2005-07-27 Thread Paolino
better. but if anybody > else has any ideas than that would be good too . > Hmm try this: http://www.itasoftware.com/careers/eng/job1.php For really useful things probably you want to reach some projects like twisted ,but there you need more experience IMO. Good luck and welcome to Python.

Re: Create a variable "on the fly"

2005-07-27 Thread Paolino
x27;;' is not used for one expression in one line. Probably the tutorial is good to be read also. Paolino -- http://mail.python.org/mailman/listinfo/python-list

Re: Create a variable "on the fly"

2005-07-27 Thread Paolino
x27;;' is not used for one expression in one line. Probably the tutorial is good to be read also. Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a dictionary from an object

2005-07-23 Thread Paolino
Thanos Tsouanas wrote: > On Sat, Jul 23, 2005 at 12:06:57PM +0200, Paolino wrote: > >>use getattr(self.obj,key) possibly, as __getattribute__ gets total >>control on attribute access > > > Thanks, but what do you mean by 'total control'? > Probably

Re: "Aliasing" an object's __str__ to a different method

2005-07-23 Thread Paolino
Little less ugly: In [12]:class A(object): : def __str__(self):return self.__str__() : def str(self):return 'ciao' : def setStr(self):self.__str__=self.str : In [13]:a=A() In [14]:a.setStr() In [15]:str(a) Out[15]:'ciao' The point is str(ob) builtin l

Re: Getting a dictionary from an object

2005-07-23 Thread Paolino
Thanos Tsouanas wrote: > Hello. > > I would like to have a quick way to create dicts from object, so that a > call to foo['bar'] would return obj.bar. > > The following works, but I would prefer to use a built-in way if one > exists. Is there one? > > class dictobj(dict): > """ > class

Re: AttributeError of a module instance

2004-12-27 Thread Paolino
Terry Reedy wrote: I'd like to catch AttributeError on the module level,so that I can declare default bindings for useds defore definition.How is this to be done? 'defore' is obviously 'before', but what is 'useds'? In and case... Unresolved bindings,possibly like >>> _rdf_type Traceback (mos

AttributeError of a module instance

2004-12-26 Thread Paolino
I'd like to catch AttributeError on the module level,so that I can declare default bindings for useds defore definition.How is this to be done?Thanks for help. Paolino -- http://mail.python.org/mailman/listinfo/python-list