Re: How do you implement this Python idiom in C++

2006-07-31 Thread alainpoint
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): self.__class__.count

Re: How do you implement this Python idiom in C++

2006-07-30 Thread alainpoint
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 post the code i

How do you implement this Python idiom in C++ ?

2006-07-27 Thread alainpoint
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 iostream using namespace std; // A base class that provides counting templateclass T class Counted { static int count;

How do you implement this Python idiom in C++

2006-07-27 Thread alainpoint
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 iostream using namespace std; // A base class that provides counting templateclass T class Counted { static int count;

Re: How do you implement this Python idiom in C++

2006-07-27 Thread alainpoint
Jon Clements wrote: [EMAIL PROTECTED] wrote: // Curious class definitions class CountedClass : public CountedCountedClass {}; class CountedClass2 : public CountedCountedClass2 {}; It apparently works but in fact it doesn't: If you derive from such a class, you get the count of the

Re: How do you implement this Python idiom in C++

2006-07-27 Thread alainpoint
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

Re: How do you implement this Python idiom in C++

2006-07-27 Thread alainpoint
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

Re: comparing of python GUIĀ“s

2006-06-20 Thread alainpoint
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 with gui

Just out of curiosity: Which languages are they using at Google and what for?

2006-06-19 Thread alainpoint
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

Re: challenging (?) metaclass problem

2006-04-11 Thread alainpoint
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

Re: challenging (?) metaclass problem

2006-04-11 Thread alainpoint
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

challenging (?) metaclass problem

2006-04-10 Thread alainpoint
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

Re: challenging (?) metaclass problem

2006-04-10 Thread alainpoint
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):

Re: DO NOT USE JAVA BECAUSE IT IS NOT OPEN SOURCE

2006-04-03 Thread alainpoint
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

Re: Is this possible in Python? SOLUTION FOUND

2006-03-14 Thread alainpoint
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): import

Re: Is this possible in Python? SOLUTION FOUND

2006-03-14 Thread alainpoint
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 for the tip. Meanwhile, I found

Re: Is this possible in Python?

2006-03-14 Thread alainpoint
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 stdin, line 1, in ? File stdin, line 3, in magic TypeError:

Is this possible in Python?

2006-03-13 Thread alainpoint
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

Re: Is this possible in Python?

2006-03-13 Thread alainpoint
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 evaluation

Re: Is this possible in Python?

2006-03-13 Thread alainpoint
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

Re: Is this possible in Python?

2006-03-13 Thread alainpoint
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

class variables for subclasses tuple

2006-03-08 Thread alainpoint
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==p[2]

Re: class variables for subclasses tuple

2006-03-08 Thread alainpoint
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): ... x =

Re: class variables for subclasses tuple

2006-03-08 Thread alainpoint
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: class variables for subclasses tuple

2006-03-08 Thread alainpoint
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

Python interpreter bug

2005-10-07 Thread alainpoint
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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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)

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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 --

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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

Re: Python interpreter bug

2005-10-07 Thread alainpoint
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 between mutables and

Elementtree and CDATA handling

2005-06-01 Thread alainpoint
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

Bug in Elementtree/Expat

2005-05-17 Thread alainpoint
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): !DOCTYPE svg PUBLIC

Re: Bug in Elementtree/Expat

2005-05-17 Thread alainpoint
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 Explorer.

Re: Which is easier? Translating from C++ or from Java...

2005-03-28 Thread alainpoint
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