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
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
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
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
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
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
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
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
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:
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
>>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
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
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:
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
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 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
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
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
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
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
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
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
Having email trouble...
--
Presenting:
mediocre nebula.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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),
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
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
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:
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
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
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)
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
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
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
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
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
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
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:
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
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
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
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,
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
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
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
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
50 matches
Mail list logo