[issue12332] Float division

2011-06-14 Thread Carmine Paolino
New submission from Carmine Paolino paolino.carm...@alice.it: Trying to run this simple script: for i in range(10): print(i*0.2) when i is 3, the result given is 0.6001. What could the problem be? -- components: Interpreter Core messages: 138311 nosy: cancelliere

[issue12332] Float division

2011-06-14 Thread Carmine Paolino
Carmine Paolino paolino.carm...@alice.it added the comment: When I try to run 3*0.2 in Python shell or using an IDLE document, the result given is 0.6001. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12332

[issue12332] Float division

2011-06-14 Thread Carmine Paolino
Carmine Paolino paolino.carm...@alice.it added the comment: Thank you for your help. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12332

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 __getattribute__(self,attr

Re: Add lists to class?

2005-09-02 Thread Paolino
AttributeError 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: algorithm for non-dimensionalization

2005-08-26 Thread Paolino
^2][T^-2] v=[L][T^-1] f=[T^-1] p=[m][L][T^-1] .. in the mass,lenght,time space are [1,2,-2] [0,1,-1] [0,0,-1] [1,1,-1] say matrix D then D*[x1,x2,x3,x4]=[0,0,0] (looking for adimensionals) So you are looking for an eigenvector formed by only integers. Ciao Paolino

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

2005-08-19 Thread Paolino
(boundMethod.im_func) class cls(object): def __init__(self): print methodId(self.meth1) print methodId(self.meth2) def meth1(self): pass def meth2(self): pass c = cls() print methodId(c.meth1) print methodId(c.meth2) I think this is giving what you expected. Regards Paolino

An observer pattern application.

2005-08-18 Thread Paolino
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 appreciated. Regards Paolino

Re: dict duplicity

2005-08-18 Thread Paolino
real keys comparisons via '==' among the keys of the bin identified by the hash of the key. Regard Paolino ___ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo

A (unpythonic) pythonable mixin recipe.

2005-08-16 Thread Paolino
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://mail.python.org/mailman/listinfo

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

2005-08-16 Thread Paolino
Paolino -- http://mail.python.org/mailman/listinfo/python-list

Re: catching all exceptions

2005-08-13 Thread Paolino
case: Handling all other exceptions: # nice-to-have: try: something() except *, e: print some error occurred: , type(e), str(e) except Exception:# catch them all. Then use moudule 'traceback' to inspect Paolino

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: __getattribute__ for class object

2005-08-12 Thread Paolino
,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: simpli int/str problem

2005-08-12 Thread Paolino
not accep dict['int_name'] in SQL variable but when i convert this variable to the str , python accepts but i cannot insert that into database because database only accept int in `BH ` thanks. Try use: SQL = INSERT INTO (`AH`, `BH` ) VALUES ('%s,%d)%(dict['str_name'],dict['int_name']) Paolino

Re: Bug on Python2.3.4 [FreeBSD]?

2005-08-12 Thread paolino
Uwe Mayer wrote: posted mailed 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

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

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() f.add(s) f.remove(s) the add succeeds the remove fails eventually not calling hash(s). Why don't

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. class clusterable(str): def __abs__(self

Re: namespaces

2005-08-10 Thread Paolino
(__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-10 Thread Paolino
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 ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it

Re: Why is this?

2005-08-10 Thread Paolino
This confuses me also,looks like empty lists share same object. 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 not this behave like the below: a, b = [[]]*2 a==b True Ooops I should write 'a is b' And, just to add to my confusion: [[]]*2

help in algorithm

2005-08-10 Thread Paolino
([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

namespaces

2005-08-09 Thread Paolino
# 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: 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.: Got it,thanks. Then there is no way of having

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

2005-08-08 Thread Paolino
usable,and has 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

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

2005-08-07 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 like that. The specialness of globals and locals was part

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

2005-08-06 Thread Paolino
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 ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB

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 var=4 is not searched outside and var[0]=4 yes? Because var=4 rebinds the name var

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 ___ Yahoo! Mail:

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 from generic namespaces. Methods seems not to have a writeble one,while functions as George

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 'polluting' the module namespace. do you want __all__

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,table=string.maketrans(badcars,'_'*len(badcars))): return

Re: doctest bug with nested triple quotes

2005-08-01 Thread Paolino
') 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

namespaces

2005-07-31 Thread Paolino
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 ___ Yahoo! Messenger

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 parse that sentence. I show you a piece of code I need

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.Recalculating

Re: namespaces

2005-07-31 Thread Paolino
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 the sense I prefer, times are gone for me for that. ) Paolino

Re: namespaces

2005-07-31 Thread Paolino
(): function.foo='something' a=function.foo Traceback (most recent call last): File stdin, line 1, in ? AttributeError: 'function' object has no attribute 'foo' How should I read it? The namespace is half done inside the function? Thanks Paolino ___ Yahoo

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

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

2005-07-29 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 = {} def fun1(): foo =

Re: Ten Essential Development Practices

2005-07-29 Thread Paolino
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 ___ Yahoo! Mail

Re: Advanced concurrancy

2005-07-28 Thread Paolino
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

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: Create a variable on the fly

2005-07-27 Thread Paolino
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: Create a variable on the fly

2005-07-27 Thread Paolino
is good to be read also. Paolino -- http://mail.python.org/mailman/listinfo/python-list

Re: any thing to do???

2005-07-27 Thread Paolino
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. Paolino -- http://mail.python.org/mailman/listinfo

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 ;) --

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 list

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 using

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 using

Re: can list comprehensions replace map?

2005-07-27 Thread Paolino
comprehension? (Or, more generally, what is the best way to do this without 'map'?) [Paolino] Probably zip should change behaviour,and cover that case or at least have another like 'tzip' in the __builtins__ .Dunno, I always thought zip should not cut to the shortest list. Heck

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: 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

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 nothing to do with your question :( But: 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 (most

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