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
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
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[&
,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
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
;
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
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
set of highly coupled interfaces useful for humans to
describe a task.
Ciao Paolino
--
http://mail.python.org/mailman/listinfo/python-list
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
"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)
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
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
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
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:
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
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()
>>
>
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
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
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
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
__
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
__
)
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
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.:
>
>
'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
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
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
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
'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
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
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
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
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
>&
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
__
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
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
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
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
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
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
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
_
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
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
>
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
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
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
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
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
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
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:/
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.
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
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
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
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
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
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
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
57 matches
Mail list logo