The standard is to use `cls`. In the __new__ method you can use `mcl` or `meta`.
--
http://mail.python.org/mailman/listinfo/python-list
I have the following module implementing a registry of functions with a
decorator:
$ cat x.py
registry = {} # global dictionary
def dec(func):
registry[func.__name__] = func
print registry, id(registry)
return func
if __name__ == '__main__':
import xlib
print registry, id(re
On Tuesday, October 9, 2012 5:24:17 PM UTC+2, Peter Otten wrote:
> Seriously, you shouldn't use the main script as a library; it is put into
>
> the sys.modules cache under the "__main__" key. Subsequent imports under its
>
> real name will not find that name in the cache and import another ins
dvice is welcome!
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ShiningPanda looks really really cool. I need to investigate it.
--
http://mail.python.org/mailman/listinfo/python-list
This may get you started (warning: not really tested).
$ echo instr.py
from warnings import warn
oget = object.__getattribute__
tget = type.__getattribute__
class Instr(object):
class __metaclass__(type):
def __getattribute__(cls, name):
clsname = tget(cls, '__na
Python 3.2 enhanced contextlib.contextmanager so that it is possible to
use a context manager as a decorator. For instance, given the
contextmanager factory below
@contextmanager
def before_after():
print(before)
yield
print(after)
it is possibile to use it to generate decorators:
@b
Here is an example by using my own library plac
(http://pypi.python.org/pypi/plac):
class Server():
def configure_logging(self, logging_file):
pass
def check(self):
pass
def deploy(self):
pass
def configure(self):
pass
def __init__(self, hostnam
On Friday, May 27, 2011 10:49:52 AM UTC+2, Ben Finney wrote:
> The exquisite care that you describe programmers needing to maintain is IMO
> just as much a deterrent as the super-is-harmful essay.
Worth quoting. Also I think this article may encourage naive programmers along
the dark path of coop
The fact that even experienced programmers fail to see that
super(type(self),self) in Python 2 is NOT equivalent to super()
in Python 3 is telling something.
--
http://mail.python.org/mailman/listinfo/python-list
He is basically showing that using mixins for implementing logging is not such
a good idea, i.e. you can get the same effect in a better way by making use of
other Python features. I argued the same thing many times in the past. I even
wrote a module once (strait) to reimplement 99% of multiple
There is a trick that I use when data transfer is the performance killer. Just
save your big array first (for instance on and .hdf5 file) and send to the
workers the indices to retrieve the portion of the array you are interested in
instead of the actual subarray.
Anyway there are cases where m
pdb plus plus: https://pypi.python.org/pypi/pdbpp
--
https://mail.python.org/mailman/listinfo/python-list
On Sunday, May 29, 2016 at 4:42:17 PM UTC+2, Ankush Thakur wrote:
> Hello,
>
> I'm a self-taught programmer who has managed to claw his way out of Python
> basics and even covered the intermediate parts. But I feel I have a ton of
> theory in my head and would like to see some smallish applicati
I did not know about docopt. It is basically the same idea of this recipe I
wrote about 12 years ago:
https://code.activestate.com/recipes/278844-parsing-the-command-line/?in=user-1122360
Good that it was reinvented :-)
--
https://mail.python.org/mailman/listinfo/python-list
n poking around in new and inspect, but it is not
> appearing like an easy task.
It is not that easy, but you can leverage on my decorator module
which does exactly what you want:
http://www.phyast.pitt.edu/~micheles/python/decorator.zip
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
nk Terry's recollection is pretty close to the "historical
truth".
Guido could have decided two years ago, sparing us the PEP 308 ordalia.
So, I am happy that at the end we will have a conditional operator, but
I
am not happy of how the process worked out. It was just an enormous
Is there a way to send a SIGINT/KeyboardInterrupt to a
Python process (knowing the pid) that works both on Unix and Windows?
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
rs StopIteration is
automatically trapped, i.e.
def g():
yield 1
raise StopIteration
yield "Never reached"
only yields 1. Not sure if this is documented behavior, however, of if
it is an implementation
accident. Anybody who knows?
Michele Simionato
--
htt
asily abused (see Zope 2) and as a consequence
you get spaghetti-inheritance, where you have objects with methods
inherited from everywhere. So be very careful if you want to use
mixins; often you can go without them.
Just my 2 Euro cents,
Michele Simionato
--
http://mail.python.org/ma
ll am not sure
> if I gained anything or not.
Nowadays I tend to use delegation via __getattr__ instead of multiple
inheritance.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
I am having a hard time in finding out how to retrieve information
about
the *size* of files I want to download from an FTP site. Should I
send a QUOTE SIZE command to the ftp server or is there an easier way?
TIA,
Michele Simionato
--
http://mail.python.org/mailman/listinfo
usage example, see the sanity.py test
script" but there is not such a script in the distribution :-(
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Yes, it works fine, thanks (still I am a bit surprised there is not
ftpparse.py but only
an _ftpparse.so).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
formats, it tells me the wininst format
> is a windows installer.
I can confirm that it works (for pure Python applications), since I did
it.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
> Could anyone suggest an open source project that has particularly well
> written Python? I am especially looking for code that people would
> describe as "very Python-ic".
I vote for the "doctest" code in the standard library.
Michele Simionato
--
h
Can somebody provide an example of how to retrieve a https url, given
username and password? I don't find it in the standard documentation.
TIA,
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Tom Anderson:
>> I have no idea what Scheme is, but I'll cettainly look it up as soon as
>> I'm done writing this.
> You won't like it. Give yourself another 5-10 years, and you might start
> to find it strangely intriguing.
+1 ;-)
Michele Simionato
-
ted
the lower level of abstraction).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Alex Martelli:
> Michele Simionato:
>> cutting off non-essential features (and you can discover that a feature
>> is non essential only after having implemented it)
> This one is difficult if you have RELEASED the program with the feature
> you now want to remove, sigh.
Gerhard wrote:
> http://initd.org/pub/software/pysqlite/doc/usage-guide.html
Can I suggest you to use a larger font for the code?It is pretty
difficult to parse with my
current screen resolution. BTW, pysqlite2 is pretty cool ;)
Michele Simionato
--
http://mail.python.
BTW, O'Reilly just published an article of mines on twill:
http://www.onlamp.com/pub/a/python/2005/11/03/twill.html
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
qwwwee:
> By the way, are you aware that C. Titus Brown (twill's author)
> tells "peste e corna" of Zope?
No, but I am not surprised. I also say "peste e corna" of Zope ;)
In general I am an anti-frameworks guy (in good company with
many Pythonistas including Guido
> which feature of python do you like most?
It makes easy things easy, while keeping hard things possible.
--
http://mail.python.org/mailman/listinfo/python-list
sudo apt-get install python2.4-tk
--
http://mail.python.org/mailman/listinfo/python-list
Javascript. So, I don't think there is a real
solution
for this kind of problem as of today (I would love to be wrong,
though).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
with PostgreSQL for 2
> years, and with Python for 6 months.
> Thank you,
Since Psyco is meant to speedup Python code, whereas the psycopg
adapter is
C-coded, I strongly doubt you will get any improvement from the
combination.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
insically HARD to support. If you can avoid it, avoid it. This will
probably make
your application more maintanable.
I your case, I would go with the keyword argument suggestion.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
I tried Kubuntu and Debian (in the trivial to install version known as
Knoppix/Kanotix)
and I like Debian more, but this is just me.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Just wrote:
> In article <[EMAIL PROTECTED]>,
> Simo Melenius <[EMAIL PROTECTED]> wrote:
>
> > I've sometimes replaced sys.stdout (and/or sys.stderr) to
> > capture/redirect debugging information in existing code that has
> > unwisely just "print"ed error and warning messages, instead of
using
>
and explain what __stdout__ is intended
for?
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ly really small.
It also takes a little time to evaluate it. I suggest you to give a
look
at it.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Maybe a PSF grant would help? I guess this has been considered ...
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
But then I have THREE published recipes!!
Does that mean that I get three free copies of the cookbook ? ;-)
Michele
--
http://mail.python.org/mailman/listinfo/python-list
f8')
>>> print german_ae # dunno if it will appear right on Google groups
ä
>>> german_ae.decode('latin1')
Traceback (most recent call last):
File "", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u
rgot to post ;-)
http://www.python.org/psf/grants/
The one about the docs seems more about teaching scientists how to use
Python.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Yep, I did the same and got confused :-/
Michele
--
http://mail.python.org/mailman/listinfo/python-list
... ;)
I should probably ask for an unicode primer, I have found the
one by Marc André Lemburg
http://www.reportlab.com/i18n/python_unicode_tutorial.html
and I am reading it right now.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
se to ship
modified Python distributions, with missing modules or splitted in n
separated packages
to download separately.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
nce you cite descriptors, what's wrong with Raimond Hetting
documentation?
http://users.rcn.com/python/download/Descriptor.htm
The only problem I see is that it is not integrated with the official
docs, but this is a
minor issue, I think.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
serious trouble with urpmi and lots of Python packages
are
available.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
> Would you like the source with your function?
Yes, since I asked for this feature something like two years ago ;-)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
that
you can use something like
__metaclass__ = MyMetaclass.with(*args) # classmethod returning a
metaclass
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
the link right now, but there are threads about the
scope rules in
python-dev, with various people protesting and Guido saying that he
wants to
keep them as they are.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
e only language I know supporting massive
parallelization ...)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
e it easy .
I will not dispute the Timbot assessment ;) He is also right that
people have
already undergone under this level of torture: see
http://tinyurl.com/6m373
for instance.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
e_and_bind("tab: complete")
but I don't find a list of recognized key bindings. For instance, can I
would
like to bind shift-tab to rlcompleter, is that possible? Can I use
function
keys? I did various attempt, but I did not succed :-(
Is there any readline-guru here with some good po
Uhm ...
>>> class C(object):
... pass
...
>>> setattr(C, "è", "The letter è")
>>> getattr(C, "è")
'The letter \xe8'
;-)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
facility to manage callbacks in
the standard
library, then I would live pretty well without lambdas.
Just IMHO, YMMV, etc.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ange(128)
So you are right after all, but I though most people didn't know that
you can have
valid identifiers with accented letters, spaces, and non printable
chars.
> setattr(C, " ", "this works")
> getattr(C, " ")
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ther reasons if I think a bit more, but these
should suffice for the moment ;)
What I would be interested in is a Lisp/Scheme implementation
compiling to Python bytecode, but I am not aware of any project
in that direction.
Michele Simionato
P.S. some pointers for people interested on the topic
lobals()["è"]
1
> According to the language reference, identifiers can only contain
letters a-z and A-Z,
> digits 0-9 and underscore.
>http://docs.python.org/ref/identifiers.html
The parser has this restriction, so it gets confused if it finds "è".
But the underl
f of CPython bytecode. It would make much
> more sense to have a Python implementation that compiles Python to
> S-expressions and then lets a high performance Lisp or Scheme system
> take care of the rest.
This is a bizarre idea if you want to make Python run faster. It is not
so bizarre
if what you want is to have access to Python from Lisp/Scheme in the
same sense
Jython has access to Java.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
mental scripts for
learning purpose. So I agree that the need does not occur often, but it
is still an useful thing to have.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
What's the simplest way to write an FTP Server in Python?
A short research on the newsgroup and on the Cookbook did not
bring out anything relevant (but I hear a little voice in the
back of my head saying Twisted, Twisted! ...)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/p
Do you have a code snippet/pointer so I have an idea of how to use it?
M.S.
--
http://mail.python.org/mailman/listinfo/python-list
> If you're after a simple FTP server, have a look at medusa.
Uhm ... Medusa does not seem actively maintained nowadays.
M.S.
--
http://mail.python.org/mailman/listinfo/python-list
believe
Python is the definitive language, and it is probabily possible
to introduce something better. It is just that nothing of the
kind appeared until now, but I keep watching at the horizon ;)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Peter Maas:
>[EMAIL PROTECTED] schrieb:
>> Davor is right: even if
>> you do not want to use it, the stuff is *there* and somebody in your
>> team will. So definitely there is an audience of programmers that
just
>> do not have an use for all the sophistication and actually are
>> penalized by it.
> "Perfection is achieved, not when there is nothing more to add, but
> when there is nothing left to take away."
Thanks, that was it! ;)
--
http://mail.python.org/mailman/listinfo/python-list
we will
have colonies on Mars") We all know how it ended :-(
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Just submitted a recipe with this goal in mind:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/365606
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Google is your friend.
This has been discussed a lot in the past. For instance, google for the
thread,
"Exceptions as New Style Classes", there was also a PEP by Steven
Taschuk,
IIRC.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
in alpha.
Don't let
the "alpha" scares you: that means that the documentation is still a
bit rough and
few things are not fully settled down, but the framework is very much
usable.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
r something like that?
I could do that in various way, but I don't see the obvious one,
maybe because I am not a Dutch ;)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
>From what I see in the docs, registering a script just normalize the
shebang line, but does not install it in
/usr/bin, nor make any symbolic links, so it is not
what I am looking for.
I guess I need to add a os.link(src, dst) somewhere in the
setup.py script or in a postinstallation script but I
Sylvain Thenault:
> Actually it does install it is $PREFIX/bin.
Aha! And how do I set $PREFIX? Is it a Unix environment variable or is
it
a keyword argument in setup? Something like setup( prefix="/usr") ?
--
http://mail.python.org/mailman/listinfo/python-list
In this case I have used hasattr(obj, "__iter__") instead of
isinstance(obj, list)
(strings are iterable but do not have __iter__ method). I think hasattr
is much better
since it works for tuples and custom iterables too.
Michele Simionato
--
http://mail.python.org/mailma
ter(X)
does not throw an exception". Objects following the __getitem__
protocol
- such as strings -are iterables even if they do not have an __iter__
method.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
est showing us what you get and what you would like to get?
Michele Simionato
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
harder to build a useful application and fully comment it
A part the Cookbook, I know of at least two Python books taking the
approach you describe:
1. Dive into Python (Pilgrim)
2. Programming Python (Lutz)
Dive into Python is free (and even translated in Italian on
www.python.it, IIRC)
Fuzzyman:
> So Lisp is for really good programmers, and Python is for
> mediocre programmers ?
Python is *also* for mediocre programmers. I see this as a
strength, not as a weakness.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Use twill:http://www.idyll.org/~t/www-tools/twill.html
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
>I am mostly
>using old style (without type unification) init but this motivate the
>shift for the new style. Is there somewhere a document about this?
Yes, see http://www.python.org/2.3/mro.html by yours truly
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
nce).
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ybe this is just wishful thinking ...
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
,
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ard Python.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
y on the childrens, dependending
on their state. Perhaps I would need more information to understand
what
you have in mind.
But at the end my point is "I would not feel much more constrained
in expressivity if I did not have multiple inheritance in Python,
and actually I have found out that th
e "", line 1
dummy = '''
^
SyntaxError: EOF while scanning triple-quoted string
**********
Is this a know bug? Any workaround? Thanks for comments,
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
sense, actually, but for some reason I would never have
thought
of it (I did not expect doctest to be so smart to strip the dots even
inside a string).
Thanks for the feeback and the quick solution,
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
#x27;, '.', '.', '.', '.']
"""
import time, threading
def example():
thread.out = []
while thread.running:
time.sleep(.01)
thread.out.append(".")
thread = threading.Thread(None, example)
if __name__ == "__main
ly cannot understand the reason for such message. Why
it
is so misleading? Can something be done about it?
TIA,
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
If you feel it's necessary to let threads spawned by a
> doctest run beyond the time doctest completes, you can arrange to
> invoke DocTestRunner.run() with clear_globs=False.
Perfect, this answers my question and gives me an useful tip about
doctest
globals.
Thanks a lot!
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
1. Mateusz Loskot:
>I would like to ask some scientists or students
>which GUI toolkit they would recommend
>to develop scientific prototypes (for education and
>testing some theories).
My vote is for ipython + matplotlib. Very easy and very powerful.
Michele Simiona
There are also my lectures at Oxford:
http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_wondersofpython.zip
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
ttr = 1
print s["x"].attr # => 1
s.close()
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
xample;")
#print c.fetchall()
c.close()
if __name__ == "__main__":
conn = sqlite.connect(DBFILE)
writedb(conn)
readdb(conn)
conn.close()
os.remove(DBFILE)
I get UnicodeDecodeError: 'utf8' codec can't decode byte 0xec in
position 3: une
Well, I have used factories of properties external to the class many
times,
and they work pretty well.
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
1 - 100 of 896 matches
Mail list logo