Re: Ternary plus

2010-02-09 Thread Martin Drautzburg
Carl Banks wrote: You can have __add__ return a closure for the first addition, then perform the operation on the second one. Example (untested): class Closure(object): def __init__(self,t1,t2): self.t1 = t1 self.t2 = t2 def __add__(self,t3): # whole

Ternary plus

2010-02-08 Thread Martin Drautzburg
Just for the hell of it ... I can easily define __plus__() with three parameters. If the last one is optional the + operation works as expected. Is there a way to pass the third argument to + -- http://mail.python.org/mailman/listinfo/python-list

Re: new.instancemethod __iter__

2010-02-07 Thread Martin Drautzburg
Steven D'Aprano wrote: If you want iterator operations similar to itertools, why does this mean you need to replace anything? Just create your own iterators. Or use pre-processing and post-processing to get what you want. Can you show an example of what you would like to happen? Steven,

Re: new.instancemethod __iter__

2010-02-07 Thread Martin Drautzburg
Christian Heimes wrote: If you *really* need to overwrite __iter__ on your instance rather than defining it on your class, you need to proxy the method call: class MyObject(object): def __iter__(self): return self.myiter() obj = MyObject() obj.myiter = myiter That should

Re: new.instancemethod __iter__

2010-02-07 Thread Martin Drautzburg
Steve Holden wrote: y = s1*2 + s2(align=10) which should iterate as Time=1,'a' Time=2,'a' Time=10,'b' I have no difficulty passing align to the object (using __call__) and use it while I furnish my own __iter__() method. However I don't quite see how I can do this with bare

new.instancemethod __iter__

2010-02-06 Thread Martin Drautzburg
Hello all When I create an Object and set its __iter__ method from outside s = Sequence #one of my own classes s.__iter__ = new.instancemethod(f,s,Sequence) I get different results, depending on whether I call for x in y.__iter__(): print x or for x in y: print x The first case

Re: A.x vs. A[x]

2010-01-23 Thread Martin Drautzburg
Terry Reedy wrote: On 1/22/2010 2:29 PM, Martin Drautzburg wrote: This has probably been asekd a million times, but if someone could give a short answer anyways I's be most grateful. What is it that allows one to write A.x? If I have a variable A, I know you can do this with classes

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
Steven D'Aprano wrote: I think this really is the correct solution for your problem. In Python, the standard place to have such public constants is at the module level, not the function or class. I think you're worrying unnecessarily about namespace pollution -- the module namespace is

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
Carl Banks wrote: I see. Well, Python is a poor choice for defining an internal DSL (i.e., DSL using the general language's syntax), because it's (deliberately) rigid in both grammar and semantics. I had this impression too. Paul McGuire should be by to recommend PyParsing shortly. I

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
On 22 Jan., 11:56, Roald de Vries r...@roalddevries.nl wrote: Hi Martin, On Jan 21, 2010, at 8:43 AM, Martin Drautzburg wrote: Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume certain values, e.g.        def move (direction

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
Mark Dickinson wrote: On Jan 21, 10:57 pm, Martin Drautzburg martin.drautzb...@web.de wrote: Here is a complete expample using a decorator, still a bit noisy def move(aDirection): print moving + aDirection #Here comes the decorator def scope(aDict): def save(locals): [...] Have you

A.x vs. A[x]

2010-01-22 Thread Martin Drautzburg
This has probably been asekd a million times, but if someone could give a short answer anyways I's be most grateful. What is it that allows one to write A.x? If I have a variable A, then what to I have to assign to it to A.x becomes valid? Or even further: what do I have to do so I can write

Re: Symbols as parameters?

2010-01-22 Thread Martin Drautzburg
Martin Drautzburg wrote: with scope(): # ... # use up, down, left, right here # up, down, left, right no longer defined after the with block exits. Just looked it up again. It's a cool thing. Too bad my locals() hack would still be required. The result would be less noisy

Re: Symbols as parameters?

2010-01-21 Thread Martin Drautzburg
Thanks for all the answers. Let me summarize (1) I fail to see the relevance of   def move( direction ): ...   print( move + str( direction ) ) ...   move( up ) move up not only in the context of my question. And I don't see an abuse of the language either. Maybe this could pass as a Zen

Re: Symbols as parameters?

2010-01-21 Thread Martin Drautzburg
Here is a complete expample using a decorator, still a bit noisy def move(aDirection): print moving + aDirection #Here comes the decorator def scope(aDict): def save(locals): Set symbols in locals and remember their original state setSymbols={} unsetSymbols=[]

Symbols as parameters?

2010-01-20 Thread Martin Drautzburg
Hello all, When passing parameters to a function, you sometimes need a paramter which can only assume certain values, e.g. def move (direction): ... If direction can only be up, down, left or right, you can solve this by passing strings, but this is not quite to the

Lost in __setstate__() in C++ and swig

2007-09-11 Thread Martin Drautzburg
I am trying to cPickle/unpickle a C++ extension class with some private data members. I wrote __getstate__() and __setstate__ in C++ (I have to, due to the private data). Pickling writes the following file: ccopy_reg _reconstructor p1 (cpyramid MidiBytes

Re: Dictionaries and dot notation

2007-04-23 Thread Martin Drautzburg
Alex Martelli wrote: Martin Drautzburg [EMAIL PROTECTED] wrote: mydata = data( ) mydata.foo = 'foo' mydata.bar = 'bar' print mydata.foo print mydata.bar I am aware of all this. Okay let me rephrase my question: is there a way of using dot notation without having to create

Re: serializable object references

2007-04-23 Thread Martin Drautzburg
Gabriel Genellina wrote: En Sun, 22 Apr 2007 12:47:10 -0300, Martin Drautzburg [EMAIL PROTECTED] escribió: I was thinking that it would be nice if a web application could talk to real objects. The client side does not need to know the internals of an object, it acts as a view for server

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Martin Drautzburg
George Sakkis wrote: Yes, there is: use an ORM to do the SQL generation for you. Check out SQLAlchemy, it will buy you much more than what you asked for. Might look, though in general I don't like OR mappers much. Having SQL generated feels as strange as having python code generated. Too much

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Martin Drautzburg
Peter Otten wrote: def SQL(sql): ...     print sql ... a = SQL(module) module # that one was obvious class A: ...     b = SQL(class) ...     def method(self, c=SQL(default arg)): ...             d = SQL(method) ... You are my hero. Indeed very cool! --

Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Martin Drautzburg
I would like to validate sql strings, which are spread all over the code, i.e. I run (prepare) them against a database to see if it happy with the statements. Spelling errors in sql have been a major pain for me. The statements will not be assembled from smaller pieces, but they will not

Dictionaries and dot notation

2007-04-22 Thread Martin Drautzburg
This may be pretty obvious for most of you: When I have an object (an instance of a class Foo) I can access attributes via dot notation: aFoo.bar however when I have a dictionary aDict = {bar:something} I have to write aDict[bar] What if I want to create a

Re: sql to xml

2007-04-22 Thread Martin Drautzburg
Tim Golden wrote: 2) Don't use XML if you don't need to. I would call this advice a golden rule the violation of which has caused serious pain in some of the projects I am working on. -- http://mail.python.org/mailman/listinfo/python-list

Re: favourite IDE

2007-04-22 Thread Martin Drautzburg
azrael wrote: Some time ago I posted a question about the favourite IDE. I finally found it. WING IDE i the best I've ever seen for python. Yes WingIde is cool but it is not free. A fairly good alternative is the pydev plugin for eclipse. --

serializable object references

2007-04-22 Thread Martin Drautzburg
Is it possible to convert an object into a string that identifies the object in a way, so it can later be looked up by this string. Technically this should be possible, because things like __main__.Foo instance at 0xb7cfb6ac say everything about an object. But how can I look up the real object,

Re: serializable object references

2007-04-22 Thread Martin Drautzburg
Gabriel Genellina wrote: En Sun, 22 Apr 2007 08:07:27 -0300, Martin Drautzburg [EMAIL PROTECTED] escribió: Is it possible to convert an object into a string that identifies the object in a way, so it can later be looked up by this string. Technically this should be possible, because things

Re: Dictionaries and dot notation

2007-04-22 Thread Martin Drautzburg
mydata = data( ) mydata.foo = 'foo' mydata.bar = 'bar' print mydata.foo print mydata.bar I am aware of all this. Okay let me rephrase my question: is there a way of using dot notation without having to create a class? -- http://mail.python.org/mailman/listinfo/python-list

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Martin Drautzburg
Peter Otten wrote: Martin Drautzburg wrote: I would like to validate sql strings, which are spread all over the code, i.e. I run (prepare) them against a database to see if it happy with the statements. Spelling errors in sql have been a major pain for me. def validateSQL(filename=None

Re: Dictionaries and dot notation

2007-04-22 Thread Martin Drautzburg
Daniel Nogradi wrote: What if I want to create a datastructure that can be used in dot notation without having to create a class, i.e. because those objects have no behavior at all? A class inheriting from dict and implementing __getattr__ and __setattr__ should do the trick... It

unicode and __repr__()

2007-04-18 Thread Martin Drautzburg
I am using repr() to pass arrays, dicts and combinations therof to javascript as it already returns a valid javascript expression (a string) right away. But for some reason it does not handle Umlaute correctly and those characters finally appear as two strange characters on the browser. I am using

Re: Everything is a distributed object

2006-10-10 Thread Martin Drautzburg
Steve Holden wrote: Unfortunately the overhead of supporting distribution is way too high to want to invoke it between two objects living in the same process. Well I was thinking along the lines of object and proxy-object where a proxy object is a handle to a remote object. Sending a

Everything is a distributed object

2006-10-09 Thread Martin Drautzburg
Hello all, I've seen various attempts to add distributed computing capabilities on top of an existing language. For a true distributed system I would expect it to be possible to instantiate objects of a remote class or to subclass a remote class and other stuff like this. My impression is that

Re: Complementary language?

2004-12-27 Thread Martin Drautzburg
HackingYodel [EMAIL PROTECTED] writes: Does any single language do a better job in Python's weaker areas? Would anyone care to suggest one to supplement Python. My first real OO language was Smalltalk. But the existing Smalltalk implementations all have some severe shortcomings. Either they

wxTreeCtrl checking for valid IDs

2004-12-27 Thread Martin Drautzburg
I have run across a weired problem: I am using a wxTreeCtrl with a model for each tree node. The tree expands lazily and each time a node is expanded, its children (Views) are completely rebuilt, creating new IDs. The children register their respecive models using two self written classes Model

Garbage collector strategy

2004-12-22 Thread Martin Drautzburg
Just for curiosity: does python use a mark-and-sweep garbage collector or simple reference counting? In the latter case it would not garbage collect circular references, right ? For mark-and-sweep, I assume there must be a toplevel Object from which all other objects can be accessed or they will

Code without effect (wx demo TreeCtrl.py ImageList)

2004-12-20 Thread Martin Drautzburg
In the wx demoy TreeCtrl.py I find the following code, that should have no effect but seems to be needed nevertheless. class TestTreeCtrlPanel(wx.Panel): def __init__(self, parent, log): [...} self.tree = MyTreeCtrl(self, tID, wx.DefaultPosition, ... isz = (16,16)

accessing module global vars by name

2004-12-19 Thread Martin Drautzburg
Withing a module I can assign a value to a global var by assigning to it in the outermost scope. Fine. But how can I do this if the attribute name itself is kept in a variable. Once the module is loaded I can access the module's namespace no problem, but inside the module the dictionary is not