Help with super()

2006-01-12 Thread David Hirschfield
I'm having trouble with the new descriptor-based mechanisms like super() and property() stemming, most likely, from my lack of knowledge about how they work. Here's an example that's giving me trouble, I know it won't work, but it illustrates what I want to do: class A(object): _v = [1,2,3

Re: Help with super()

2006-01-12 Thread David Hirschfield
this is totally made-up pseudo-code): class A: v = [1,2] class B(A): v = [2,3] class C(B): v = [4,5] c = C() c.getv() ==> [1,2,2,3,4,5] -Dave Paul McNett wrote: > David Hirschfield wrote: > >> I tried that and super(B,self), but neither works. >> >> Usi

Re: Help with super()

2006-01-13 Thread David Hirschfield
ve Paul McNett wrote: > David Hirschfield wrote: > >> Is there a way to get what I'm after using super()? > > > Probably. > > >> The idea is that I could have a chain of subclasses which only need >> to redefine _v, and getting the value of v as a prop

Re: Help with super()

2006-01-13 Thread David Hirschfield
uper(), it should be the same as using the class name itself - both will result in or whetever self is an instance of. I still don't see a way to accomplish my original goal, but any other suggestions you might have would be appreciated. Thanks, -David Mike Meyer wrote: >David H

Newbie to XML-RPC: looking for advice

2006-01-13 Thread David Hirschfield
I've written a server-client system using XML-RPC. The server is using the twisted.web.xmlrpc.XMLRPC class to handle connections and run requests. Clients are just using xmlrpclib.ServerProxy to run remote method calls. I have a few questions about the performance of xmlrpc in general, and spe

Re: instance attributes not inherited?

2006-01-15 Thread David Hirschfield
Nothing's wrong with python's oop inheritance, you just need to know that the parent class' __init__ is not automatically called from a subclass' __init__. Just change your code to do that step, and you'll be fine: class Parent( object ): def __init__( self ): self.x = 9 class C

Preventing class methods from being defined

2006-01-15 Thread David Hirschfield
Here's a strange concept that I don't really know how to implement, but I suspect can be implemented via descriptors or metaclasses somehow: I want a class that, when instantiated, only defines certain methods if a global indicates it is okay to have those methods. So I want something like: gl

Can one class have multiple metaclasses?

2006-01-15 Thread David Hirschfield
Is it possible for one class definition to have multiple metaclasses? I don't think it is, but I'm just checking to make sure. From what I know, you can only define "__metaclass__" to set the metaclass for a class, and that's it, is that correct? -David -- Presenting: mediocre nebula. -- ht

Re: Preventing class methods from being defined

2006-01-15 Thread David Hirschfield
n Sun, 15 Jan 2006 18:41:02 -0800, >David Hirschfield <[EMAIL PROTECTED]> wrote: > > > >>I want a class that, when instantiated, only defines certain methods >>if a global indicates it is okay to have those methods. So I want >>something like:

Re: Preventing class methods from being defined

2006-01-16 Thread David Hirschfield
way to refer to the class that "is being defined" when calling a function or classmethod? So, ideas on how to accomplish that...again, greatly appreciated. -Dave Bengt Richter wrote: >On Sun, 15 Jan 2006 19:23:30 -0800, David Hirschfield <[EMAIL PROTECTED]> >wrote: > > &g

Re: Preventing class methods from being defined

2006-01-17 Thread David Hirschfield
>>bit more insight into the arrangement I'm trying to get: >> >>restrict = True >> >> >Why a global value? If it is to affect class instantiation, why not pass it >or a value to the constructor, e.g., C(True) or C(some_bool)? > > > For reasons unrelated to this problem, the class that does t

Re: Preventing class methods from being defined

2006-01-17 Thread David Hirschfield
than me, will know some way to do this, or something close to it. Thanks again, -David Bengt Richter wrote: On Mon, 16 Jan 2006 18:55:43 -0800, David Hirschfield <[EMAIL PROTECTED]> wrote: Thanks for this, it's a great list of the ways it can be done. Here's a

Chunking sequential values in a list

2006-07-13 Thread David Hirschfield
I have this function: def sequentialChunks(l, stride=1): chunks = [] chunk = [] for i,v in enumerate(l[:-1]): v2 = l[i+1] if v2-v == stride: if not chunk: chunk.append(v) chunk.append(v2) else: if not chunk:

Help with async xmlrpc design

2006-08-16 Thread David Hirschfield
I have an xmlrpc client/server system that works fine, but I want to improve performance on the client side. Right now the system operates like this: client makes request from server (by calling server.request() via xml-rpc) server places "request" on queue and returns a unique ID to the calling

Has anyone used py-xmlrpc?

2006-08-22 Thread David Hirschfield
Searching for a python xmlrpc implementation that supports asynchronous requests, I stumbled on this project: http://www.xmlrpc.com/discuss/msgReader$1573 The author is Shilad Sen, and it appears to do what I'm looking for. But I'd love some feedback from anyone who might have used it before I

Question about turning off garbage collection

2006-10-05 Thread David Hirschfield
Question from a post to pygtk list...but it probably would be better answered here: I encountered a nasty problem with an external module conflicting with my python threads recently, and right now the only fix appears to be to turn off garbage collection while the critical code of the thread is

Re: Question about turning off garbage collection

2006-10-05 Thread David Hirschfield
to create a test case that clearly demonstrates the problem so I can get the authors of the modules to find the real problem. Thanks, -Dave Tim Peters wrote: [David Hirschfield] Question from a post to pygtk list...but it probably would be better answered here: I encountered a na

Sending binary pickled data through TCP

2006-10-12 Thread David Hirschfield
I have a pair of programs which trade python data back and forth by pickling up lists of objects on one side (using pickle.HIGHEST_PROTOCOL), and sending that data over a TCP socket connection to the receiver, who unpickles the data and uses it. So far this has been working fine, but I now need

Re: Sending binary pickled data through TCP

2006-10-13 Thread David Hirschfield
implementing them myself, which is not something I have time for. Thanks again, -Dave Steve Holden wrote: David Hirschfield wrote: I have a pair of programs which trade python data back and forth by pickling up lists of objects on one side (using pickle.HIGHEST_PROTOCOL), and

Re: Sending binary pickled data through TCP

2006-10-13 Thread David Hirschfield
sync. I don't find socket code particularly nasty, especially through a higher-level module like asyncore/asynchat. -Dave Irmen de Jong wrote: David Hirschfield wrote: I have a pair of programs which trade python data back and forth by pickling up lists of objects on one s

Re: Sending binary pickled data through TCP

2006-10-13 Thread David Hirschfield
I'm using cPickle already. I need to be able to pickle pretty arbitrarily complex python data structures, so I can't use marshal. I'm guessing that cPickle is the best choice, but if someone has a faster pickling-like module, I'd love to know about it. -Dave Fredrik L

Advanced lockfiles

2006-06-12 Thread David Hirschfield
I'm not sure it's even possible to do what I'm trying to here...just because the logistics may not really allow it, but I thought I'd ask around... I want some kind of lockfile implementation that will allow one process to lock a file (or create an appropriately named lockfile that other proce

TEST IGNORE

2006-06-20 Thread David Hirschfield
Having email trouble... -- Presenting: mediocre nebula. -- http://mail.python.org/mailman/listinfo/python-list

Running code on assignment/binding

2006-06-20 Thread David Hirschfield
Another deep python question...is it possible to have code run whenever a particular object is assigned to a variable (bound to a variable)? So, for example, I want the string "assignment made" to print out whenever my class "Test" is assigned to a variable: class Test:    ... x = Test

Getting external name of passed variable

2006-06-20 Thread David Hirschfield
I'm not sure this is possible, but it sure would help me if I could do it. Can a function learn the name of the variable that the caller used to pass it a value? For example: def test(x):    print x val = 100 test(val) Is it possible for function "test()" to find out that the variable

Re: Getting external name of passed variable

2006-06-20 Thread David Hirschfield
Cool, thanks. Stack inspection of sorts it is. -Dave faulkner wrote: import sys tellme = lambda x: [k for k, v in sys._getframe(1).f_locals.iteritems() if v == x] a=1 tellme(a) ['a'] Michael Spencer wrote: David Hirschf

Deprecation wrapper

2006-06-20 Thread David Hirschfield
I have a "deprecation" wrapper that allows me to do this: def oldFunc(x,y): ... def newFunc(x,y): ... oldFunc = deprecated(oldFunc, newFunc) It basically wraps the definition of "oldFunc" with a DeprecationWarning and some extra messages for code maintainers, and also prompts them to

Help with deprecation-wrapper code

2006-06-21 Thread David Hirschfield
I have a deprecation-wrapper that allows me to do this: def oldFunc(x,y): ... def newFunc(x,y): ... oldFunc = deprecated(oldFunc, newFunc) It basically wraps the definition of "oldFunc" with a DeprecationWarning and some extra messages for code maintainers, and also prompts them t

simpleparse parsing problem

2006-09-01 Thread David Hirschfield
Anyone out there use simpleparse? If so, I have a problem that I can't seem to solve...I need to be able to parse this line: """Cen2 = Cen(OUT, "Cep", "ies", wh, 544, (wh/ht));""" with this grammar: grammar = r''' declaration := ws, line, (ws, line)*, ws line:= (statement / assignment),

Getting text into the copy-paste buffer...

2006-09-05 Thread David Hirschfield
Strange request, but is there any way to get text into the linux copy-paste buffer from a python script ? I know the standard python libraries won't have that functionality (except as a side-effect, perhaps?), but is there a simple trick that would do it on linux? A command line to get text int

Re: Getting text into the copy-paste buffer...

2006-09-05 Thread David Hirschfield
This is good info...but I'm looking for the opposite direction: I want to place some arbitrary command output text into the clipboard, not get the current selection out of the clipboard. Any help on that end? -Dave kdart wrote: David Hirschfield wrote: Strange request, b

Re: Getting text into the copy-paste buffer...

2006-09-05 Thread David Hirschfield
Ah, indeed it does...my distro didn't have it, but a quick download and compile and there it is. Thanks a bunch, -Dave Keith Dart wrote: On 9/5/06, David Hirschfield <[EMAIL PROTECTED]> wrote: This is good info...but I'm looking for the opposite direction:

Help with fast tree-like structure

2006-01-25 Thread David Hirschfield
I've written a tree-like data structure that stores arbitrary python objects. The objective was for the tree structure to allow any number of children per node, and any number of root nodes...and for it to be speedy for trees with thousands of nodes. At its core, the structure is just a list of

Re: Efficient Find and Replace

2006-01-27 Thread David Hirschfield
You aren't getting too many helpful responses. Hope this one helps: The closest python equivalent to: p = head(L) while (p) { if (p->data == X) p->data = Y; } would be: for i,v in enumerate(L): if v == X: L[i] = Y modifies the list in place. There's nothing wrong with just doing

Best way to determine if a certain PID is still running

2006-02-03 Thread David Hirschfield
I'm launching a process via an os.spawnvp(os.P_NOWAIT,...) call. So now I have the pid of the process, and I want a way to see if that process is complete. I don't want to block on os.waitpid(), I just want a quick way to see if the process I started is finished. I could popen("ps -p %d" % pid)

Question about xmlrpc and threading

2006-02-15 Thread David Hirschfield
An xmlrpc client/server app I'm writing used to be super-simple, but now threading has gotten into the mix. On the server side, threads are used to process requests from a queue as they come in. On the client side, threads are used to wait on the results of requests to the server. So the quest

Re: Question about xmlrpc and threading

2006-02-15 Thread David Hirschfield
erverProxy instance while a request is already underway? Clearer? -Dave Martin P. Hellwig wrote: >David Hirschfield wrote: > > >>An xmlrpc client/server app I'm writing used to be super-simple, but now >>threading has gotten into the mix. >> >>On the server

Help: asyncore/asynchat and terminator string

2007-01-16 Thread David Hirschfield
I'm implementing a relatively simple inter-application communication system that uses asyncore/asynchat to send messages back and forth. The messages are prefixed by a length value and terminator string, to signal that a message is incoming, and an integer value specifying the size of the messa

Using marshal to manually "import" a python module

2007-11-29 Thread David Hirschfield
I had a situation recently that required I manually load python bytecode from a .pyc file on disk. So, for the most part, I took code from imputil.py which loads the .pyc data via the marshal module and then exec's it into a newly created module object (created by imp.new_module()). The relevan

Help: Trouble with imp.load_module

2007-12-11 Thread David Hirschfield
I'm not entirely sure what's going on here, but I suspect it's related to my general lack of knowledge of the python import internals. Here's the setup: module: tester.py: - import imp def loader(mname, mpath): fp, pathname, description = imp.find_module(mname,[mpath]) tr

Starting value with raw_input

2006-04-18 Thread David Hirschfield
Does the raw_input built-in function allow giving an initial value that the user can edit? Perhaps by using the readline module? I want to do something so that I can provide the user a default value they can edit as they wish at the prompt: result = raw_input("Enter value: ") Somehow outpu

Raising a specific OSError

2006-04-21 Thread David Hirschfield
I know this should be obvious, but how does one raise a specific type of OSError? When I attempt to perform a file operation on a non-existent file, I get an OSError: [Errno 2], but what if I want to raise one of those myself? Thanks in advance, -Dave -- Presenting: mediocre nebula. -- http:

Re: Raising a specific OSError

2006-04-21 Thread David Hirschfield
I wasn't clear enough in my original post. I know how to raise a basic OSError or IOError, but what if I want to raise specifically an "OSError: [Errno 2] No such file or directory"? Somehow it must be possible to raise the error with the correct information to bring up the standard message, b

Good thread pool module

2006-03-22 Thread David Hirschfield
There isn't a thread pool module in the standard library, but I'm sure many have been written by people in the python community. Anyone have a favorite? Is there one particular implementation that's recommended? Not looking for anything fancy, just something that lets me queue up tasks to be pe

Help: Creating condensed expressions

2006-03-24 Thread David Hirschfield
Here's the problem: Given a list of item names like: apple1 apple2 apple3_SD formA formB formC kla_MM kla_MB kca_MM which is a subset of a much larger list of items, is there an efficient algorithm to create condensed forms that match those items, and only those items? Such as: apple[12] apple3

Parsing csh scripts with python

2006-03-28 Thread David Hirschfield
Is there a module out there that would be able to parse a csh script and give me back a parse tree? I need to be able to parse the script, modify some variable settings and then write the script back out so that the only changes are the variables I've modified (comments, ordering of statements,

Replacing a built-in method of a module object instance

2009-06-26 Thread David Hirschfield
I have a need to replace one of the built-in methods of an arbitrary instance of a module in some python code I'm writing. Specifically, I want to replace the __getattribute__() method of the module I'm handed with my own __getattribute__() method which will do some special work on the attribu

Determining if a function is a method of a class within a decorator

2009-06-29 Thread David Hirschfield
I'm having a little problem with some python metaprogramming. I want to have a decorator which I can use either with functions or methods of classes, which will allow me to swap one function or method for another. It works as I want it to, except that I want to be able to do some things a littl

Re: Determining if a function is a method of a class within a decorator

2009-06-29 Thread David Hirschfield
nd I'm not sure it's applicable to my case. I'd love an explanation of what is going on in that setup, and if it isn't usable for my situation, why not? Thanks again, -David Terry Reedy wrote: David Hirschfield wrote: I'm having a little problem with some python metapro

Re: Determining if a function is a method of a class within a decorator

2009-06-30 Thread David Hirschfield
6:01 pm, David Hirschfield wrote: So is there a pattern I can follow that will allow me to determine whether the objects I'm given are plain functions or belong to a class? Thanks in advance, class HomemadeUnboundMethod(object): def __init__(self,func): self.func = fu