Il giorno mercoledì 13 agosto 2014 19:13:16 UTC+2, thequie...@gmail.com ha
scritto:
> What is the difference between traits and roles?
People keep using the same names to mean different concepts. For me traits are
the things described here:
http://www.iam.unibe.ch/~scg/Archive/Papers/Scha03aTra
plac is based on argparser and it is intended to be much easier to use. See
http://plac.googlecode.com/hg/doc/plac.html
Here is an example of usage.
$ cat vcs.py
class VCS(object):
"A fictitious version control tool"
commands = ['checkout', 'commit']
def checkout(self, url):
r
On Wednesday, April 3, 2013 3:05:31 AM UTC+2, Rotwang wrote:
> After thinking about it for a while I've come up with the following
>
> abomination
Alas, there is actually no good way to implement this feature in pure Python
without abominations. Internally the decorator module does something s
I have a memory leak in a program using big arrays. With the goal of debugging
it I run into the memory_profiler module. Then I discovered something which is
surprising to me. Please consider the following script:
$ cat memtest.py
import gc
from memory_profiler import profile
@profile
def test
e(d)
and NOT a datetime.datetime.
So I need an adaptation mechanism; alternatively it would be enough for
me to be able
to redefine the __str__ representation of psycopg DateTime objects (
which are defined
at C level, so I cannot just override the __str__ method).
Any hints? I am sure there is a custom way to do this.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Kirk Strauser:
> I wrote this article which was published in Free Software Magazine:
> http://www.freesoftwaremagazine.com/free_issues/issue_09/intro_zope_1/
If find funny your headline
"""
Zope's biggest distinguishing characteristic is how closely it models
the language it is written in:
Python
he type checking I would like to avoid :-/
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Some of the reasons are explained here:
http://www.amk.ca/python/writing/why-not-zope.html
I am using the last Zope (2.8.4) at work, and the situation is slightly
better now than in the past,
but only slightly. Zope 3 looks better, but I am not sure how much
better.
Michele Simionato
Frank Millan:
> Perhaps if you explain what you are trying to do, I may be able to
> suggest something.
I am looking for an adaptation/type cast mechanism and looking at the
sources I think I have
found it in doc/examples/usercast.py. I am doing some experiment now
...
Michele Sim
Schüle Daniel wrote:
> Can someone give me some pointers to the metaprogramming in Python?
> links etc
Check the Python Wiki. For the decorators in particular I wrote a
module that
you may find useful. See
http://www.phyast.pitt.edu/~micheles/python/decorator.zip
http://www.phyast.pitt.edu/~miche
emory optimization trick and should NOT be used as
declarations.
You can find a few posts of the Martellibot on the subject. I even
wrote a recipe
to tell people who want static declarations how to implement them
without slots:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158
I like to play devil's advocate here, so I will say that in this case
using automatic testing
will increase your probability of spelling mistakes: I do most of my
spelling mistakes
in the test cases! <0.5 wink>
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
You could use py.test
--
http://mail.python.org/mailman/listinfo/python-list
be found in the tool directory of
> the py-lib.
This looks new. Can you comment on how utestconvert.py work and how
reliable is it?
Thanks,
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
> Scott David Daniels about marking expected failures:
I am +1, I have wanted this feature for a long time. FWIW,
I am also +1 to run the tests in the code order.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
> Pramod Subramanyan asked aboyt urllib2:
Look at this article:
http://www.voidspace.org.uk/python/articles/urllib2.shtml
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
t unittest is already
cumbersome how it is,
I would not touch it. Instead, I would vote for py.test in the standard
library.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
As many others, I use emacs for programming and ipython for interactive
experiments.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> I need to find out if an object is a class.
> Which is quite simply awful...does anyone know of a better way to do
> this?
inspect.isclass
M.S.
--
http://mail.python.org/mailman/listinfo/python-list
pt. of Computer Science
> http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
Look at
http://www.python.org/download/releases/2.3/mro
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
yle) == type
There should be something more on
http://www.python.org/download/releases/2.2.3/descrintro
(I have seen somewhere how type.__new__ works, and how the metaclass
is chosen, so I am pretty sure sure there are no issue, at least for
pure Python
classes).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
attr, if
you don't
want to use inheritance. It would be still better that magically
transform your
classes with a metaclass.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Michele Simionato ha scritto:
> I believe the new style system was designed to allows this sort of
> mixing and
> that there are no issues at all.
Thinking a bit more, there are no issues at all if you know what a new
style class is and if you do not expect it to work as an old-style o
Joe Knapka ha scritto:
> Classes are effectively open in Python, too, at least
> where methods are concerned, since one can do
> klass.__dict__["myMethod"]=myMethod.
Yes, but builtin classes in Python are closed and this is the relevant
point.
Michele
he attributes of a metaclass are available to its instances,
but not to the instances of the instances. Just this is the main
difference between metaclasses and superclasses."""
Since this happens for real attributes, it looks natural that the same
should
happen for 'virtual' attributes implemented via '__getattr__' or
'__getattribute__'.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
supports them. For instance this is a recent
reference for continuations in Scheme:
http://www-128.ibm.com/developerworks/linux/library/l-advflow.html?ca=dgr-lnxw02FlowControl
Ruby should have support for continuations too, but I am quite ignorant
about the Ruby literature.
Michele S
rc.pwm02 # 127
rc.pwm02 = 1312
print rc.pwm02 # 32
This is a bit hackish, but I would prefer this over a metaclass
solution. since it does not add
any hidden magic to your class.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
s (i.e. extensions classes), or try to use multiple metaclasses.
I wrote a paper
about metaclasses abuses which should be published soon or later; you
can see the draft
here:
http://www.phyast.pitt.edu/~micheles/python/classinitializer.html
Michele Simionato
--
http://mail.python.org/mailman/listinfo/
k
and you will avoid all issues of custom metaclasses. This is exactly
the approach I advocate
in the paper I referred before, so I think your solution is pretty safe
in that respect. Still I
think in this particular problem avoiding the __metaclass__ at all is
possible and it should be
preferred, just
t all.
Please, do this experiment: take all classes defined in the Python
standard library and add
to them a custom do-nothing metaclass. See what happens.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Carl Banks wrote:
> Come on, I don't think anyone's under the impression we're being
> indiscriminate here.
Ok, but I don't think that in the case at hand we should recommend a
metaclass
solution.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
he documentation:
http://docs.python.org/dev/lib/pickle-inst.html
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
om/ASPN/Cookbook/Python/Recipe/204197) but I
would rather avoid it altogether.
The problem with metaclasses is that you are adding magic to the
classes of
your USERS, and the users are known to play any kind of dirty tricks.
You
(speaking in general of you as the author of a framework) should strive
to keep things clean as much as possible.
I agree that the problems are rare: but just for this reason they are
prone to very subtle bugs, the hardest to find. And there is no
documentation of metaclass pittfall AFAIK :-(
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
and using 'type' instead (i.e.
use the __metaclass__
hook, but not custom metaclasses). It is the same trick used by George
Sakkis in this same
thread.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
gavino wrote:
> both are interpreted oo langauges..
Notice that gavino has a long history of asking trollish questions in
Lisp and Scheme
newsgroups and he displays the typical behavior of a troll.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
a while one gets used to it and if you think a bit
it makes quite a
lot sense. Also, having the self explicit, makes Python object system
better (i.e.
it goes more in the direction of CLOS and less in the direction of
Java).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
t IndexError:
if token != '':
yield token
if __name__=='__main__':
print '--- Smart Python 2.2+ tokenizer ---'
g = read_eval_yield_loop(tokenizer3, text, ' ')
for t in g:
print t
if t == 'comma':
g.send(',')
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
vars(self).update(kwargs)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Gabriel Genellina wrote:
> At Monday 13/11/2006 13:33, Michele Simionato wrote:
>
> >Alan Isaac wrote:
> > > Also, as an aside, no one objected to using
> > > self.__dict__.update(kwargs)
> > > in the __init__ function of the parameter holding class.
>
there should be an option to turns off the visualization of certain
modules, for instance the ones in given subpackages. I guess somebody
has already written it, maybe even with
a nice visual backend. Any hint?
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Dennis Benzinger wrote:
>
> I've never tried it, but http://www.tarind.com/depgraph.html looks like
> what you are looking for.
This is EXACTLY what I had in mind :-)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Maric Michaud wrote:
I would consider avoiding threads via Twisted utils.getProcessOutput:
http://twistedmatrix.com/projects/core/documentation/howto/process.html#auto6
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
thon&rnum=3#3d77eba36a97751d
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
corator.zip
http://www.phyast.pitt.edu/~micheles/python/documentation.html
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
about arguing for Emacs since everything is
already
explained here: http://www.dina.kvl.dk/~abraham/religion
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
spectful of
all the work people like Steven Bethard and others did :-(
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
in a running program with a problem you can add debug methods and
possibily
even fix the problem without restarting the program).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
classname, *attributes):
cls = type(classname, mybases, mydic)
for name, value in attributes:
setattr(cls, name, attr)
return cls
is the typical solution for your use case.
OTOH, if you are looking for use classes for metaclasses, look at the
Python Wiki
and use Google.
Michele Simionato
[EMAIL PROTECTED] wrote:
> What are the reason one would get this error: TypeError: Cannot create
> a consistent method resolution order (MRO) for bases object ??
See http://www.python.org/download/releases/2.3/mro/
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
want to ask
> how do you use this list , reading every mail come in or just read what
> you think
> interesting ?
>
> Thank you !
>
>
> Best Regard !
I use the newsgroup: http://groups.google.com/group/comp.lang.python
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
peps/pep-0359 (already rejected by
Guido).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Sylvain Ferriol wrote:
> Michele Simionato a écrit :
> >
> > See http://www.python.org/dev/peps/pep-0359 (already rejected by
> > Guido).
> >
> i do not understand the withdrawal note, what do "different level" mean ?
> do you have an example or is it py
world. Anyway, the MRO concept is documented here:
http://www.python.org/download/releases/2.3/mro/
(yes, it is not easy to find this link in python.org).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Ben Sizer wrote:
> I agree that the Python docs aren't quite as effective as reference
> material due to the lack of simple function and method lists though.
http://docs.python.org/lib/modindex.html, pydoc and ipython are more
than enough for me.
Michele Simionat
Ben Sizer wrote:
> Michele Simionato wrote:
> > Ben Sizer wrote:
> > > I agree that the Python docs aren't quite as effective as reference
> > > material due to the lack of simple function and method lists though.
> >
> > http://docs.python.org/l
Noah wrote:
> Am I the only one that finds the super function to be confusing?
No, see for instance http://fuhm.net/super-harmful/
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
;__set__'
You need to define the descriptor at the metaclass level too.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ot defined yet"
>
> regards
> David
Check also the warnings module (it will give you also line number
information for free).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
by the user in
HTML hidden widgets.
Sometimes the simplest solutions are the better ones ;)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
(I don't believe I am responding to a notorious troll ...)
One (bad) solution is to write in your sitecustomize.py the following:
$ echo /usr/lib/python/sitecustomize.py
import __builtin__
class Object(object):
def debug(self):
print 'some debug info'
__builtin__.object = Object
th
am not claiming that this is a good idea.
Michele Simionato
---
import datetime
import cherrypy as cp
# each user (but really should be each session) has her input loop
# one should disable the back button and implement an undo mechanism
def inputloop(user):
start_time = datetime.datetime.to
t the mistake. I wrote a module to avoid
this kind of issues, so you
may want to check it out:
http://www.phyast.pitt.edu/~micheles/python/documentation.html
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
cmf or plone , how could i handle this?
> thanks a lot.
>
> i'm working around this for two days and surfing a lot of pages but
> still felt confused, any suggestion would be appreciated.
This is the wrong list. See http://www.zope.org/Resources/MailingLists
Michele Simio
now
Python you
can earn your living. Heck, there are people knowing Visual Basic only
that earn
their living! ;)
Anyway, at work I use Python and SQL only (and a bit of bash and HTML).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Python only. Notice that by "knowing Python" I mean also
knowing its
standard library and the most common Python third party libraries (GUI
toolkits, XML toolkits, SQL libraries, twisted, etc. etc.)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
mmers don't.
Yep, I think that's the point. Worth repeating (and +1 for QOTW).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Ruby it is not really different from Python in terms of learning "new
ways of programming".
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
this stuff, you are likely to be able to
learn any language.
My point was that when hiring a programmer, one should also look at the
potential of the
person, not only at his/her present skills.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
t;
> import psycopg
> ImportError: No module named psycopg
>
> come mai? va settata qualche path oltre a quella di postgresql ?
>
> grazie dell'aiuto
Well, if you are using Psycopg2, do
import psycopg2
(and please use the italian mailing list for questions in Italian).
sequence of characters) and I can check hasattr(obj,
'__iter__') to distinguish
(for instance) a list of strings from a single string (typically in
recursive algorithms
working on texts).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
e, func)
return func
return decorator
@defmethod(C)
def m1(self, x):pass
help(m1)
BTW, for people with a Lisp background I recommend using IPython with
emacs and the
ipython.el mode. It is pretty good, even if not comparable to Slime.
Michele Simio
nctions and Methods" in
> http://users.rcn.com/python/download/Descriptor.htm
>
> You need to implement a __get__ method on your class.
See also
http://groups.google.com/group/comp.lang.python/browse_frm/thread/d691240a5cfebcdf/93503c5b9c66226e?lnk=gst&q=simionato+subclassing+Fu
not obj.__class__:
obj.__class__ = cls
class C(object): # old class
def m1(self):
return 1
c = C() # old instance
assert c.m1() == 1
class C(object): # new class
def m1(self):
return 2
update(c) # old instance updated
assert c.m1() == 2
27;Q'
assert c.m1() == 'Q'
assert c.__class__.__module__ == __name__ # make sure c.__class__ is
defined in the current module
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
t against extra-large one-liners.
Finally, notice that you can alwasys aliases if you are a lazy typist:
shortcut = LongClassName.LongAttributeName
This also saves an attribute access and gives you some additional
speed, which may
be useful in some cases.
Michele Simionato
--
http://mail.p
u want
persistency
(you cannot pickle a closure) so in that case I use a callable object
instead.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Timofei Shatrov wrote:
> It's not surprising that no one uses this stuff for serious work.
Well, I replaced all my unittests with doctests long ago, and I am not
the only one following this way
(see the Zope 3 project for instance).
Michele Simionato
--
http://mail.python.org
Paul Rubin wrote:
> "Alex Mizrahi" <[EMAIL PROTECTED]> writes:
>
> > "Programming Languages:Application and Interpretation"
> > Shriram Krishnamurthi
> > Brown University
> This book doesn't seem to be online.
http://cs.brown.edu/~sk/Publ
doesn't take 60 hour weeks over years to master
>
Chicken Scheme: http://www.call-with-current-continuation.org
(not sure about wx, but there are various GUI wrappers available)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Nick Maclaren wrote:
> It would be much cleaner not to have to fiddle with static
> members after the class is initialised.
You can hide the fiddling, for instance with the trick explained here:
http://www.phyast.pitt.edu/~micheles/python/classinitializer.html
Michele Simionato
--
e even if one does not care about
> memory.
See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158 (how
to freeze Python classes)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ay that you are
using the metaclass hook here, but not a "real" metaclass. Still
waiting for class decorators ...
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
http://www.phyast.pitt.edu/~micheles/python/classinitializer.html
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
The subject says it all, I would like a script to act differently when
called as
$ python script.py and when called as $ python -i script.py. I looked
at the sys module
but I don't see a way to retrieve the command line flags, where should
I look?
TIA,
Michele Simionato
--
Hendrik van Rooyen wrote:
> "Michele Simionato" <[EMAIL PROTECTED]> wrote:
>
>
> > The subject says it all, I would like a script to act differently when
> > called as
> > $ python script.py and when called as $ python -i script.py. I looked
> &g
the code written by
others.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
think of something to get yourself visibile (i.e.
contribute to some OSS
project, write articles, partecipate to conferences, etc.)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
or, "should return int"
TypeError: should return int
The reason of is that the module internally uses 'exec'. There
should be a way around
that, anyway, but I have no time to check it right now.
Still, the module may be of inspiration to you.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
I remember there was somewhere a page called "super considered
harmful", some googling
should find it. It was discussing the issue you are alluding to, as
well others. Also google
in the newsgroup, there are lots of threads about super and its
shortcomings.
Michele Simionato
production,
> maintenance and reuse costs of python code considerably, so much in fact that
> python's very slowness represents part of its competetive edge over languages
> that are in some ways better engineered and more capable.
I think you have a very good point here. +1000!
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
e every seconds.
How can I get that in a simple way? A Unix-only solution would be fine,
too.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
hat
is happening.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
of use nothing beats CherryPy, but I am not sure how stable it
is.
Quixote is nice and small, and pretty easy to use too.
Many likes Django and TurboGears.
Zope and Twisted are for people who have a lot of time to invest.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python
first point on interactive sessions, are you aware
of Michael Hudson's recipe
"automatically upgrade class instances on reload()"
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164 ?
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Replying to myself ...
I cooked up this solution involving os.pipe and os.fork, but I am not
especially happy with
it; anyway, let me write it. Feedback is welcome, since this was
written very quickly and
I may have missed something. BTW, are there libraries out there doing
something similar?
---
Tkinter is the GUI toolkit that comes with Python and is available on
all platform without any
installation effort. It is quite OK for simple things and I would
recommend it for any beginner.
Google for "An Introduction to Tkinter" by F. Lund.
Michele Simionato
--
http://mail.
about the resolution order etc.)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
> M.E.Farmer:
>Your answer lies somewhere in this page ;)
>http://www.python.org/2.2.2/descrintro.html
Yes, when it refers to
http://www.python.org/2.3/mro.html
(section Bad Method Resolution Orders).
In short, it is a feature, not a bug.
Michele Simionato
e
class. So you can override it without problems, and still access it as
type.mro(cls).
For more about metamethods see
http://www-128.ibm.com/developerworks/linux/library/l-pymeta2/index.html
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
'purpose' of classmethods.
In my personal opinion classmethods and staticmethods could (and
possibly
should) be removed from the language; a part for that consideration,
the typical
use for classmethods is as object factories, to provide alternative
constructors.
Miche
201 - 300 of 896 matches
Mail list logo