Hello,
I came accross what i think is a serious bug in the python interpreter.
Membership testing seems not to work for list of objects when these
objects have a user-defined __cmp__ method.
It is present in Python 2.3 and 2.4. I don't know about other versions.
The following code illustrates the
There is definitely a bug.
Maybe the follownig snippet is more clear:
class OBJ:
def __init__(self,identifier):
self.id=identifier
self.allocated=0
#def __cmp__(self,other):
# return cmp(other.allocated,self.allocated)
mylist=[OBJ(i) for
Sorry Fredrik but I don't understand. Just comment out the assert and
you have different results depending on whether an unrelated sort
function is defined.
This seems weird to me !
--
http://mail.python.org/mailman/listinfo/python-list
I understand this, Steve.
I thought the _cmp_ method was a helper for sorting purposes. Why is it
that a membership test needs to call the __cmp__ method?
If this isn't a bug, it is at least unexpected in my eyes.
Maybe a candidate for inclusion in the FAQ?
Thank you for answering
Alain
--
http:/
In fact, i want to sort the list based on the 'allocated attribute' and
at the same time, test membership based on the id attribute.
__cmp__ logically implies an ordering test, not an identity test. These
two notions seems to be confounded in python which is unfortunate. Two
objects could have the
No doubt you're right but common sense dictates that membership testing
would test identity not equality.
This is one of the rare occasions where Python defeats my common sense
;-(
Alain
--
http://mail.python.org/mailman/listinfo/python-list
> Steve Holden wrote:
>Consider:
>>> a = {1:'one'}
>>> b = {2:'two'}
>>> c = {1:'one'}
>>> a is c
False
>>> a in [b, c]
True
>>>
>What would you have Python do differently in these circumstances?
You mean: What i would do i if i was the benevolent dictator ?
I would make a distinction bet
Patrick Useldinger wrote:
> cjl wrote:
> Depends on what language you know best. But Java is certainly easier
to read than C++.
There is a difference between theory and practice. In theory, Java is
easier to read than C++.
In practice however, the average Java programmer is MUCH less talented
Hello,
I have the need to write the equivalent of Python class methods in C++.
Chuck Allison proposes the following
(http://www.artima.com/cppsource/simple.html):
#include
using namespace std;
// A base class that provides counting
template class Counted {
static int count;
public:
Counted()
Hello,
I have the need to write the equivalent of Python class methods in C++.
Chuck Allison proposes the following
(http://www.artima.com/cppsource/simple.html):
#include
using namespace std;
// A base class that provides counting
template class Counted {
static int count;
public:
Counted(
Jon Clements wrote:
> [EMAIL PROTECTED] wrote:
> > // Curious class definitions
> > class CountedClass : public Counted {};
> > class CountedClass2 : public Counted {};
> >
> > It apparently works but in fact it doesn't:
> > If you derive from such a class, you get the count of the parent class,
>
Rob Williscroft wrote:
> If this is more than idle curiosity I strongly suggest you post
> a version of the python code you need to translate to C++.
For the moment this is just healthy curiosity but i will still post the
code i would like to see translated:
class Parent:
count=0
Noah Roberts wrote:
> What happens if you print Parent.getcount() now?
You still get 2 since there is no new instance of Parent that was
created.
Alain
--
http://mail.python.org/mailman/listinfo/python-list
Pierre Barbier de Reuille wrote:
> [EMAIL PROTECTED] wrote:
> > Rob Williscroft wrote:
> >
> >> If this is more than idle curiosity I strongly suggest you post
> >> a version of the python code you need to translate to C++.
> >
> > For the moment this is just healthy curiosity but i will still pos
Pierre Barbier de Reuille wrote:
> [EMAIL PROTECTED] wrote:
> > Pierre Barbier de Reuille wrote:
> [...]
> >
> > I thank you for your response. The equivalent of your solution is
> > posted hereunder:
> > class cA(object):
> > count=0
> > def __init__(self):
> > sel
I know Google are using Python for testing purposes.
But for the rest ?
is it PHP or Java or .NET?
Which technology is rendering the google main page?
And of course th obvious question, why not Python?
Alain
--
http://mail.python.org/mailman/listinfo/python-list
Bayazee wrote:
> Hi
> i want some info ...
> plz tell me the benefit (or any data) of each gui (pyqt , pyqtk ,
> wxpython , tkinter ..)
> in the other hand wich one you offer (and why ?) ?
Open the following url: http://www.google.com
Enter the following: "google tutorial"
Choose a link and
Bayazee wrote:
> ThanX ...
> any idea for choosing one of them ?
> best in linux & windows
> i must write a cross platform project .
> it is a chat server and client with a user end site .
> i started by writing a web site and creating a database in MySQL (FC4)
> .
> now i want to write a client w
Hello,
I use Elementtree to parse an elementary SVG file (in fact, it is one
of the examples in the "SVG essentials" book). More precisely, it is
the fig0201.svg file in the second chapter.
The contents of the file are as follows (i hope it will be rendered
correctly):
http://www.w3.org/TR/2001/RE
Fredrik Lundh wrote:
>
> adding
>
> xmlns:xlink="http://www.w3.org/1999/xlink";
>
> to the "svg" element should make the problem go away.
Thanks for the tip. It indeed solves the problem.
Most examples in the book do not include such a declaration and yet are
properly rendered by Internet Ex
I am experimenting with ElementTree and i came accross some
(apparently) weird behaviour.
I would expect a piece of XML to be read, parsed and written back
without corruption (except for the comments and PI which have purposely
been left out). It isn't however the case when it comes to CDATA
handli
Hello,
I have got a problem that i can't readily solve.
I want the following:
I want to create a supertuple that behaves both as a tuple and as a
class.
It should do the following:
Point=superTuple("x","y","z") # this is a class factory
p=Point(4,7,9)
assert p.x==p[0]
assert p.y==p[1]
assert p.z==
Peter Otten wrote:
> [EMAIL PROTECTED] wrote:
>
> > Point.x=0 leads to having p.x==0
> > It seems not possible to have class variables and instance variable
> > having the same name and yet different values.
>
> A quick check:
>
> >>> class T(tuple):
> ... class __metaclass__(type):
> ...
As an supplement to my previous post, please find hereunder a snippet
for my unsuccessful attempt (commented out snippet does not work):
def superTuple(*attribute_names):
nargs = len(attribute_names)
class T(tuple):
def __new__(cls, *args):
re
Thank you Peter, this does the job.
In passing, I have another question: where can I read up more on
metaclasses?
Alain
--
http://mail.python.org/mailman/listinfo/python-list
Hi
I wonder if Python is capable of the following: define a function which
returns its argument.
I mean:
def magic_function(arg):
.. some magic code ...
that behaves the following way:
assert magic_function(3+4)=="3+4"
assert magic_function([i for i in range(10)])=="i for i in range(
Kay Schluehr wrote:
> Storing arguments away before they are evaluated doesn't work in
> Python. You have to hack the compiler in order to access the parsetree.
> You might take a look at the compiler package of the standard library
> that enables access to ASTs. Thus you could define lazy evaluat
Hello again,
I am disappointed. You are the experts, you've got to try harder ;-)
What i want is a generalisation of this tiny function:
import tokenize
import token
def magic_function(s):
readline = open(s.gi_frame.f_code.co_filename).readline
for t in
tokenize.generate_tokens(open
Hi Kent,
My intention is to be able to retrieve any line of code in a running
program, in the following way:
def magic_funct(s):
for line in file(s.gi_frame.f_code.co_filename):
print line
magic_funct(i for i in [1,2,3])
I just find it stupid to be obliged to use a generato
jalanb wrote:
> You might like the version here:
> http://www.jorendorff.com/toys/out.html
>
> Especially the "need to know" presentation, which is cute
>
> --
> Alan
> http://aivipi.blogspot.com
Thank you for the tip.
Meanwhile, I found a shorter solution to my problem:
def magic(arg):
i
Kay Schluehr wrote:
> [EMAIL PROTECTED] wrote:
> > jalanb wrote:
> > > You might like the version here:
> > > http://www.jorendorff.com/toys/out.html
> > >
> > > Especially the "need to know" presentation, which is cute
> > >
> > > --
> > > Alan
> > > http://aivipi.blogspot.com
> >
> > Thank you f
Steven D'Aprano wrote:
>
> Doesn't work for me either:
>
> >>> def magic(arg):
> ... import inspect
> ... return inspect.stack()[1][4][0].split("magic")[-1][1:-1]
> ...
> >>> magic(3+4)
> Traceback (most recent call last):
> File "", line 1, in ?
> File "", line 3, in magic
> TypeErro
Bravo, yoo r write, a propriatary languish is an oxy-moron. I have a
rekwest zou: witch languish do yoo rekomend, bikoos yoo seem so a grate
programor, at list zis is wat eye beleve, judging by yoo spelling.
Alain
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I have what in my eyes seems a challenging problem.
Thanks to Peter Otten, i got the following code to work. It is a sort
of named tuple.
from operator import itemgetter
def constgetter(value):
def get(self): return value
return get
def createTuple(*names):
class TupleT
Now, a tab-free version of my previous post. (Sorry for the
inconvenience)
Hi,
I have what in my eyes seems a challenging problem.
Thanks to Peter Otten, i got the following code to work. It is a sort
of named tuple.
from operator import itemgetter
def constgetter(value):
def get(self): r
Hi Peter,
I don't know if you noticed but i changed my mind and removed the post
as i realised that people seemed to have much more interest in how
relevant c code still is than in solving an interesting problem.
I only speak French and Dutch and my knowledge of Belgium's third
official language
Hi Peter,
I don't know if you noticed but i changed my mind and removed the post
as i realised that people seemed to have much more interest in how
relevant c code still is than in solving an interesting problem.
I only speak French and Dutch and my knowledge of Belgium's third
official language
37 matches
Mail list logo