Re: Help with Windows build of Yapgvb Python extension

2008-01-11 Thread Lonnie Princehouse
On Jan 11, 9:44 am, Mike <[EMAIL PROTECTED]> wrote: > On Jan 11, 8:41 am, Lonnie Princehouse <[EMAIL PROTECTED]> > wrote: > > > > > I'm the author of Yapgvb, a Python binding for Graphviz. Yapgvb > > enjoys modest success, but for some time it has bee

Help with Windows build of Yapgvb Python extension

2008-01-11 Thread Lonnie Princehouse
I'm the author of Yapgvb, a Python binding for Graphviz. Yapgvb enjoys modest success, but for some time it has been in dire need of a Python 2.5 build for Windows. I'm posting this message in the hopes of finding someone who is interested in making this build. This is a relatively quick task for

list comprehensions put non-names into namespaces!

2006-05-25 Thread Lonnie Princehouse
List comprehensions appear to store their temporary result in a variable named "_[1]" (or presumably "_[2]", "_[3]" etc for nested comprehensions) In other words, there are variables being put into the namespace with illegal names (names can't contain brackets). Can't someone come up with a bette

Re: How to guess the language of a given textstring?

2006-05-15 Thread Lonnie Princehouse
A search to see how many words from the text belong to english/german/spanish common word dictionaries would be an easy way to get a crude guess at the language. -- http://mail.python.org/mailman/listinfo/python-list

Re: Deferred Evaluation in Recursive Expressions?

2006-05-09 Thread Lonnie Princehouse
The first 'typedef' line will have a NameError when it tries to evaluate LinkedListB -- http://mail.python.org/mailman/listinfo/python-list

SOAP server with WSDL?

2006-04-24 Thread Lonnie Princehouse
Does anyone know of a Python SOAP package that will publish a SOAP service /and/ generate a corresponding WSDL file? Looking at SOAPpy and ZSI, it seems that their WSDL support is limited to client-side stuff. -- http://mail.python.org/mailman/listinfo/python-list

Re: minidom + wxPython woes

2006-04-10 Thread Lonnie Princehouse
I'm hesitant to resort to tricks like "import pyexpat before wx, so that symbols are loaded from the right library". Luckily, I stumbled onto pxdom. It's a pure-python DOM implementation, and switching to it was as easy as this: # import xml.dom.minidom as dom import pxdom as dom -- http://mai

Re: how to make a generator use the last yielded value when it regains control

2006-04-10 Thread Lonnie Princehouse
In general, you're right - if speed is a concern, loops should be used instead of recursion in Python when possible. In this case, the recursive overhead is insignificant compared to the expense of iterating over the sequence at every iteration. By the time there are 70 stack frames of recursion

Re: how to make a generator use the last yielded value when it regains control

2006-04-10 Thread Lonnie Princehouse
> What's wrong with the following ? > > def morris(seed,n) : > """...""" > for k in xrange(n-1) : > seed=length_encode(seed) > return seed Nothing's wrong with it. I happen to think the recursive version is more elegant, but that's just me ;-) -- http://mail.python.org/mailm

Re: minidom + wxPython woes

2006-04-07 Thread Lonnie Princehouse
Oops, I missed a bracket... that should read: testxml = '' But it still crashes ;-) -- http://mail.python.org/mailman/listinfo/python-list

minidom + wxPython woes

2006-04-07 Thread Lonnie Princehouse
Hi all, I'm getting a seg fault when I try to use minidom to parse some XML inside a wxPython app. I was wondering if someone else could run the simple code below on Linux and, if it doesn't crash horribly, post which versions of (Python, wxPython) they are using? I can't find other messages rel

Re: Screen placement based on screen resolution

2006-04-07 Thread Lonnie Princehouse
Tkinter takes strings as its arguments; it's TCL's legacy. You can use string formatting for this: x = width/2-40 y = height/2-30 root.geometry('%ldx%ld+%ld+%ld' % (width, height, x, y)) -- http://mail.python.org/mailman/listinfo/python-list

Re: how to make a generator use the last yielded value when it regains control

2006-04-06 Thread Lonnie Princehouse
Here's my take on the thing. It only prints one term, though. http://www.magicpeacefarm.com/lonnie/code/morris.py.html (a bit too long to post) -- http://mail.python.org/mailman/listinfo/python-list

Re: how to make a generator use the last yielded value when it regains control

2006-04-06 Thread Lonnie Princehouse
The generator in your original post /does/ rebind seed, but only on the last iteration of the loop. You'll need to wrap that loop in another loop if you want the generator to yield more than once. As for "communicating" with a generator --- e.g. telling it to stop --- this might be done by passin

Re: ``pickling'' and ``unpickling''

2006-04-05 Thread Lonnie Princehouse
Pickling is the Python term for serialization. See http://en.wikipedia.org/wiki/Serialization Suppose you want to save a Python object "x" to a file... output_file = open('my_pickle', 'wb') # open a file import pickle pickle.dump(x, output_file) # write x to the file output_file.close() ...

Re: A SANE scanner backend written in Python?

2006-03-28 Thread Lonnie Princehouse
Recompile Python and SANE with debugging enabled, if you haven't already. That should allow you to trace back to the source of the error using gdb (or your favorite gdb front-end). AFAIK there's no inherent reason that embedding Python in a shared library wouldn't work.Did you try compiling th

Re: overlapping sets

2006-03-24 Thread Lonnie Princehouse
There is a sets.Set class built in to Python. You might want to use this instead of lists. It defines some handy set operations like intersection, union, and so on. from sets import Set my_sets = { 'one' : Set([0,4,7,9]), 'two' : Set([0,3,7,9]), etc... } -- http://mail.python.org/mailm

Re: user-supplied locals dict for function execution?

2006-03-20 Thread Lonnie Princehouse
> Beautiful is better than ugly. > Explicit is better than implicit. >> Err... I see no contradiction nor conflict here. What to do when explicit is ugly and implicit is beautiful? Aye, there's the rub. ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: user-supplied locals dict for function execution?

2006-03-20 Thread Lonnie Princehouse
Very clever! This looks like exactly what I wanted. Thanks =) -- http://mail.python.org/mailman/listinfo/python-list

Re: user-supplied locals dict for function execution?

2006-03-20 Thread Lonnie Princehouse
Occaisionally, the first two lines of The Zen of Python conflict with one another. An API I'm working on involves a custom namespace implementation using dictionaries, and I want a pretty syntax for initializing the custom namespaces. The fact that these namespaces are implemented as dictionaries

Re: user-supplied locals dict for function execution?

2006-03-20 Thread Lonnie Princehouse
> What's your use case exactly ? I'm trying to use a function to implicitly update a dictionary. The whole point is to avoid the normal dictionary semantics, so kw['x'] = 5 unfortunately won't do. I think bytecode hacks may be the way to go -- http://mail.python.org/mailman/listinfo/python-lis

user-supplied locals dict for function execution?

2006-03-20 Thread Lonnie Princehouse
Can anyone think of a way to substitute a user-supplied dictionary as the local dict for a function call? e.g. def f(): x = 5 d = {} exec_function_in_dictionary( f, d ) # ??? print d["x"] # 5 #-- Right now, the way I'm doing this is to parse the function body out of it

Re: python newbie, linux novice, needs to run spamassassin

2006-03-16 Thread Lonnie Princehouse
I don't know spamassassin's exact set up, but usually procmail spam filters read an email message from standard input and produce an exit code that tells you if the message is spam or not. So from the Python side, it should be as easy as running whatever the command is (a quick googling suggests i

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-15 Thread Lonnie Princehouse
It looks like a good start! Some tips- - Index your arrays starting from 0 instead of 1. It will make life easier (and it's the convention in most modern languages) - Try a two dimensional array for the board representation? A list of lists will do: brd = [ [0] * 5 for i in xrange(5) ]

Re: Tree and Graph structures in Python.

2006-03-14 Thread Lonnie Princehouse
Google for "boost graph python" -- http://mail.python.org/mailman/listinfo/python-list

Re: Very, Very Green Python User

2006-03-13 Thread Lonnie Princehouse
> Python closures are apparently very poor, but from what I can surmise > of the PyGTK2 page, instances of objects are dynamic enough to add new > methods, so you get your callbacks, at least. It's true that Python's "lambda" is somewhat limited, but this is rarely a problem because you can define

Re: time series calculation in list comprehension?

2006-03-10 Thread Lonnie Princehouse
Well, you could iterate over an index into the list: from __future__ import division def moving_average(sequence, n): return [sum(sequence[i:i+n])/n for i in xrange(len(sequence)-n+1)] Of course, that's hardly efficient. You really want to use the value calculated for the i_th term in

Re: Help with a reverse dictionary lookup

2006-03-09 Thread Lonnie Princehouse
I made a logic error in that. Must be tired :-( Alas, there is no undo on usenet. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with a reverse dictionary lookup

2006-03-09 Thread Lonnie Princehouse
The parsing is good; the structure can be transformed after the parsing is done. The basic problem with the "reverse lookup" search is that you need to iterate over lots of things. If you're only doing one search, that's not too horrible But if you're going to perform multiple searches, you can

Re: Help with a reverse dictionary lookup

2006-03-09 Thread Lonnie Princehouse
Here's the illegible gibberish version of your function. Once you understand completely the following line of code, you will be well on your way to Python nirvana: getNodes = lambda Foundry=None,Process=None: [node for node,foundries in dict.iteritems() if ((Foundry is None) and ((Process is None

Re: Simulation Programming Skills and Python

2006-03-06 Thread Lonnie Princehouse
Object oriented languages lend themselves fairly well to this sort of modeling, and a strong programmer in any language should be able to take a good description of a well thought-out model and write some code for it. However, by far the harder part is designing a good model. Asking whether all p

automatic html generation for documentation?

2006-02-24 Thread Lonnie Princehouse
I plan on writing some documentation that will consist of blocks of commentary with interspersed snippets of syntax-colored Python code and the occaisional image. Does anyone know of a package that will take a high level description of what I just described and auto-generate clean-looking web page

ANN: yet another python graphviz binding (yapgvb) 1.1.1

2006-02-22 Thread Lonnie Princehouse
Introducing Yapgvb, a Python wrapper around the AT&T's graph layout library Graphviz. Features: - A nice clean Pythonic interface - Boost.Python wrapper around the C libraries; no more fiddling with system calls to dot. - Read and write .dot files using Graphviz's own library routines. - T

Re: Merging two lists of data (Pythonic way)

2006-02-16 Thread Lonnie Princehouse
You might consider writing two classes to represent the values in list1 and list2. It might be more Pythonic than sloshing around all of those lists and dictionaries. But as it is, it looks like you want to find matching pairs of lists and dictionaries from list1 and list2, respectively: # index

Re: equivalent functions?

2006-02-10 Thread Lonnie Princehouse
Very close... it is equivalent to: apply_each = lambda fns, args=[]: [f(*args) for f in fns] The asterisk in f(*args) expands the sequence to fill the arguments to f, where as f(args) would pass the args as only the first argument to the function. apply is deprecated, replaced by the syntax:

Re: any way to customize the is operator?

2006-02-10 Thread Lonnie Princehouse
> Why did you want to customize "is"? Well, mostly out of principle ;-) But also because I'm wrapping a C library which passes around C structs which are wrapped in shim C++ classes for a Boost.Python layer. Boost Python does a marvelous job of translating between Python and C++ data types; when

appending to a list via properties

2006-02-10 Thread Lonnie Princehouse
Here's a curious hack I want to put up for discussion. I'm thinking of writing a PEP for it. Observation - I found myself using this construct for assembling multiple lists: foo = [] qux = [] while some_condition: a, b = calculate_something() foo.append

Re: is there a better way?

2006-02-10 Thread Lonnie Princehouse
everybody is making this way more complicated than it needs to be. storage = list[:list.index(O)] incidentally, "list" is the name of a type, so you might want to avoid using it as a variable name. -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the public callables of self

2006-02-09 Thread Lonnie Princehouse
Ha! I didn't realize that was getmembers' implementation. What a hack ;-) In fact, your way is faster, since getmembers is taking the time to sort its results (presumably so that repeated calls to the same object will yield the same list; I don't think dir has a guaranteed ordering) -- http://

Re: Finding the public callables of self

2006-02-09 Thread Lonnie Princehouse
import inspect myCallables = [name for name, value in inspect.getmembers(self) if not name.startswith('_') and callable(value)] Instance methods aren't in self.__dict__ because they're a part of the class. To made a comprehensive list of all the attributes available to an instance, you have to t

Re: any way to customize the is operator?

2006-01-26 Thread Lonnie Princehouse
> (objects are not allowed to lie about who they are, or what they are). Dangit! I need to find a less honest programming language. Anyone have a Perl cookbook handy? ... -- http://mail.python.org/mailman/listinfo/python-list

any way to customize the is operator?

2006-01-26 Thread Lonnie Princehouse
There doesn't seem to be any way to customize the behavior of "is" as can be done for other operators... why not? -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with fast tree-like structure

2006-01-25 Thread Lonnie Princehouse
> A = [, B, C] >B = [, D] >C = [] Why store node data in the same list that contains the children? It seems like the OO approach would be more extensible, e.g. class Node: def __init__(self): self.children = [] # list of nodes # store node data as attributes... # If you wa

Re: Augmented generators?

2006-01-10 Thread Lonnie Princehouse
AFAIK there's no way to have "yield" produce anything other than a generator. You could achieve the syntax you want with a decorator, although under the hood it would still be iterating over a (key,value) tuples so there's not really any point. class GeneratorTupleWrapper: def __init__(self, g):

Re: ANNOUNCE; Try python beta

2005-12-19 Thread Lonnie Princehouse
Pretty neat =) But aren't you concerned about security? Letting anybody execute arbitrary Python expressions (and therefore also arbitrary system commands?!) on your box --- even from within a FreeBSD jail --- seems a bit dangerous. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using printf in a C Extension

2005-12-09 Thread Lonnie Princehouse
printf will generally work in C extensions (although, as others have said, it goes to STDOUT which is not necessarily the same as Python sys.stdout) Try explicitly flushing the buffer with fflush(stdout) -- http://mail.python.org/mailman/listinfo/python-list

Re: 3-dimensional plot in Python?

2005-11-15 Thread Lonnie Princehouse
Google for "MayaVi" It's overkill for what you've described (it doesn't even make 2D graphs afaik), but it could draw your function as a 3D surface. And besides, it's way cool. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python music interfaces

2005-11-10 Thread Lonnie Princehouse
Are you talking about audio files (wav, mp3) or MIDI? Converting audio files into discrete notes ("music recognition") is seriously non-trivial, although there are some commercial products you might be able to use for this. On the other hand, you could draw a spectrographs without too much troub

Re: wxPython newbie question, creating "mega widgets" , and DnD

2005-11-10 Thread Lonnie Princehouse
Yes, wx.Panel. > A side question - why is their a EVT_LIST_BEGIN_DRAG but no > EVT_LIST_END_DRAG, unlike tree's which have BEGIN and END? I need a > draggable list box, and would prefer to not handle low level mouse > events. Dunno. There is an EVT_LIST_COL_END_DRAG, though, maybe that will hel

Re: What do you use as symbols for Python ?

2005-11-10 Thread Lonnie Princehouse
I use custom classes and the "is" operator... that way, things don't get confused with integers, and I have an object where repr(state) will give me more than an integer. (the integer approach works well enough but seems like a case of "I can program C in ANY language!") opened = type('opened', (

Re: help make it faster please

2005-11-10 Thread Lonnie Princehouse
The word_finder regular expression defines what will be considered a word. "[a-z0-9_]" means "match a single character from the set {a through z, 0 through 9, underscore}". The + means "match as many as you can, minimum of one" To match @ as well, add it to the set of characters to match: wor

Re: help make it faster please

2005-11-10 Thread Lonnie Princehouse
You're making a new countDict for each line read from the file... is that what you meant to do? Or are you trying to count word occurrences across the whole file? -- In general, any time string manipulation is going slowly, ask yourself, "Can I use the re module for this?" # disclaimer: unteste

Re: Pythonising the vim (e.g. syntax popups)

2005-11-09 Thread Lonnie Princehouse
There is a Python folding script, as someone already mentioned. That will help you track indentation, although it's not perfect (iirc, long triple quoted strings cause folding malfunctions) I don't know of any way to get dynamic help about functions, although it seems like an ideal use of Vim's b

Re: C extension + libm oddity [fmod(2.0, 2.0) == nan ?!]

2005-11-04 Thread Lonnie Princehouse
> Have you compiled the C extension with all optimization turned off? Yes. The C extension's objects are compiled only with the debugging flag and -fPIC for position indepdendent code, necessary for shared objects. No optimization. The only things that have any optimization are Python and glib

C extension + libm oddity [fmod(2.0, 2.0) == nan ?!]

2005-11-04 Thread Lonnie Princehouse
I've been trying to debug this for two days now, and it's a longshot but I'm hoping that someone here might recognize a solution. I've got a C extension which calls a function in a C library, which calls another function in another library, which calls another function, which calls fmod from the s

Re: reload fails if module not in sys.path

2005-10-21 Thread Lonnie Princehouse
> That's OK, but you may find fiddling with sys.path is more productive :-) Yeah, that's what I'm doing and it works just fine. When I stumbled over this behavior yesterday it seemed (and still does) like a low-priority bug in reload. I was hoping a guru would reply with something like, "Of cour

Re: reload fails if module not in sys.path

2005-10-21 Thread Lonnie Princehouse
It's not just load_module. Reload fails on modules imported normally if their paths are no longer in sys.path. Easy to reproduce example: bash$ mkdir module_dir bash$ touch module_dir/plugin.py bash$ python Python 2.4.1 (#1, Sep 25 2005, 15:12:45) [GCC 3.4.3 20041125 (Gentoo 3.4.3-r1, ssp-3.4.3-

reload fails if module not in sys.path

2005-10-20 Thread Lonnie Princehouse
So, it turns out that reload() fails if the module being reloaded isn't in sys.path. Maybe it could fall back to module.__file__ if the module isn't found in sys.path?? ... or reload could just take an optional path parameter... Or perhaps I'm the only one who thinks this is silly: >>> my_module

Re: Python GUIs

2005-09-21 Thread Lonnie Princehouse
B is a tuple if it's assigned that way. Tuples are immutable. To make a list instead, you need square brackets: B = ['\x12', '\x32'] Regarding your original post, you'll probably have to ask more specific questions if you want to get good answers. -- http://mail.python.org/mailman/listinfo/p

Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-14 Thread Lonnie Princehouse
Yes. With the unbuffered flag, raw_input() strings on my box end in \r. -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-14 Thread Lonnie Princehouse
After doing some more reading, I now think this isn't a bug. Evidently the unbuffered flag not only makes stdin unbuffered, but it also forces it into binary mode. I didn't realize that when I posted earlier. So the SyntaxErrors arise because the interpreter isn't converting \r\n into \n because

Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-13 Thread Lonnie Princehouse
Will do -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows Python 2.4: Unbuffered flag causes SyntaxError on interactive sessions?

2005-09-13 Thread Lonnie Princehouse
Weird. Did you build Python yourself? The 2.4.1 release on python.org is from March 30. I just tried ActiveState's 2.4.1... the same thing happens. -- http://mail.python.org/mailman/listinfo/python-list

Re: wxPython StyledTextCtrl and tabs?

2005-09-13 Thread Lonnie Princehouse
That's exactly what I was looking for. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Windows Python 2.4: Unbuffered flag causes SyntaxError on interactive sessions?

2005-09-13 Thread Lonnie Princehouse
>From the cmd shell on both Windows 2k and XP, I'm getting this weird syntax error in conjunction with the unbuffered flag. It works fine without -u. Has anyone else encountered it? This didn't happen with Python 2.2... C:\>python -u Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit

wxPython StyledTextCtrl and tabs?

2005-09-13 Thread Lonnie Princehouse
Does anyone know of a way to make the wxPython StyledTextCtrl expand tabs into spaces? (yes, I'm trying to use it to edit Python code :P) -- http://mail.python.org/mailman/listinfo/python-list

Re: How to print the name of a list?

2005-08-22 Thread Lonnie Princehouse
In general, no --- there is no unique mapping between references and names. For debugging, however, it is sometimes useful to try this kind of reverse lookup by iterating over the global dictionary: def guess_name(thing): for name, reference in globals.iteritems(): if thing is referen

Re: Why does __init__ not get called?

2005-08-09 Thread Lonnie Princehouse
What kinds of illegal date values are you trying to represent? The reason I ask is that it's not going to be as easy as subclassing datetime... datetime is implemented in C. and so enforcement of legal values is going to be in the C code. For the time.h functions, you're also going to be constra

Re: Import question

2005-08-09 Thread Lonnie Princehouse
Circular import issues can usually be resolved by moving import statements into the bodies of functions which aren't executed when the module itself is imported. Simple example: fileA.py -- import fileB as fb foo = 10# we're going to access foo from fileB fb.do_something_with_foo()

Re: Why does __init__ not get called?

2005-08-08 Thread Lonnie Princehouse
Uh... are you actually trying to instantiate this class? mydate = DateTime(2005, 8, 8) The reason I ask is that __init__ /is/ called when I run your code on Python 2.4, provided that the above line is added to the end. -- http://mail.python.org/mailman/listinfo/python-list

Re: Parallel arithmetic?

2005-08-04 Thread Lonnie Princehouse
There are many ways to do this. None of them avoids looping, technically, although you can easily avoid the "for" syntax. -- Simple but wastes some memory c = [i-j for i,j in zip(a,b)] -- Using itertools.izip (python 2.3) c = [i-j for i,j in itertools.izip(a,b) ] -- Generator expression

Re: 2.3 or 2.4 on linux

2005-08-04 Thread Lonnie Princehouse
> I assume some system tools must use them, even if I don't. I don't know if > I can just copy all this into the 2.4 site-packages (deleting .pyc and .pyo) > and get what I need. Copying pure python site-packages from python23 to python24 should be safe, but the binaries (.so) will not work becau

Re: Filtering terminal commands on linux

2005-07-29 Thread Lonnie Princehouse
Firstly, there's probably a better way to do whatever you're trying to do w.r.t cd/dvd burning. I'm not familiar with gear, but its webpage lists "Batch file scripting capability" as a feature, which suggests that you might be able to do what you want without parsing output intended for humans. T

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Lonnie Princehouse
> Is there some equivalent feature in Python regexps? cpp_pat = re.compile('(/\*.*?\*/)|(".*?")', re.S) def subfunc(match): if match.group(2): return match.group(2) else: return '' stripped_c_code = cpp_pat.sub(subfunc, c_code) ...I suppose this is what the Perl code might do, but

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Lonnie Princehouse
> Is there some equivalent feature in Python regexps? cpp_pat = re.compile('(/\*.*?\*/)|(".*?")', re.S) def subfunc(match): if match.group(2): return match.group(2) else: return '' stripped_c_code = cpp_pat.sub(subfunc, c_code) ...I suppose this is what the Perl code might do, but

Re: PyGTK or wxPython (not a flame war) on Windows

2005-07-25 Thread Lonnie Princehouse
I haven't used PyGTK very much, so I can't comment on it. My last impression of GTK-on-Windows was that it wasn't very stable and didn't blend well with the Windows native look and feel, but that was a while ago and it has probably improved a great deal since then. I use wxPython, doing my develo

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-11 Thread Lonnie Princehouse
IIRC, the self.__dict__.update(locals()) trick confuses psyco. But you can make a decorator to achieve the same result. There's not really a convincing case for extending python syntax. def attribute_decorator(f): import inspect argnames = inspect.getargspec(f)[0] def decorator(*arg

Re: Creating Python wrapper for DLL

2005-06-28 Thread Lonnie Princehouse
ctypes! http://starship.python.net/crew/theller/ctypes/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Any way to not create .pyc files?

2005-06-09 Thread Lonnie Princehouse
> You didn't really describe the nature of the problem. Perhaps the whole > .pyc thing is a bit of a red herring, and the real problem lies > elsewhere? What are the actual symptoms of your problem? Yes, the .pyc thing could be a red herring. I was hoping to find an easy way to disable them to

Re: Any way to not create .pyc files?

2005-06-09 Thread Lonnie Princehouse
>> PEP 304 would have helped, but it appears to be deceased. > Not sure it's deceased (a dead parrot?) - it's on the standards track, > it hasn't been rejected, and Skip has actually provided a patch to > implement the solution. It is possible that PEP 304 is really just pining for the fjords, bu

Re: Any way to not create .pyc files?

2005-06-09 Thread Lonnie Princehouse
Of course! ZIP imports! I think that will solve the problem nicely. We already have a starter application that locates the codebase on the network drive, so it wouldn't be too hard to implement the "keep a local copy up to date" solution. But I'll try the zip idea first. Many thanks for your h

Any way to not create .pyc files?

2005-06-09 Thread Lonnie Princehouse
In short: Is there any way to run Python WITHOUT trying to create .pyc files (or .pyo) or to have Python not attempt to import the .pyc files it finds? Reason: We have a site-specific package installed on a network drive[1]. When anyone with write access imports this package, the network drive

Re: Function Serialization

2005-06-01 Thread Lonnie Princehouse
By default, shelve uses pickle to serialize objects.Pickle doesn't actually serialize functions... it just saves the function's name and name of its defining module, and upon loading attempts to find that function again. This is pretty much /never/ going to work the way you want it to if you'r

Re: speeding up Python script

2005-05-18 Thread Lonnie Princehouse
Quick tip- Try xrange instead of range. This will use dramatically less memory if your search space is large, which will speed things up /if/ your machine is being forced to swap. Besides that, without seeing the code for your functions, it's hard to offer more advice. Your algorithm is necess

Re: Python features

2005-05-12 Thread Lonnie Princehouse
> Quoting from that link: > There are three main types of programming languages. > > * Imperative > * Functional > * Declarative > Aren't functional languages a subset of declarative? (c.f. http://en.wikipedia.org/wiki/Declarative_programming) -- http://mail.python.org/mailman/l

Re: Need a little parse help

2005-05-10 Thread Lonnie Princehouse
write() doesn't automatically add a newline like print does. You can either do: outputfile.write(words[1] + '\n') or print >> outputfile, words[1] -- http://mail.python.org/mailman/listinfo/python-list

Re: python and glut

2005-05-05 Thread Lonnie Princehouse
Welcome to the exciting world of trying to make graphics work on Linux =) DRI is direct rendering. The Module section of your XF8Config should have: Load "glx" Load "dri" Load "GLCore" That probably won't solve things. Google for some combination of ("debian" + "xfree86" + your vide

Re: how can I sort a bunch of lists over multiple fields?

2005-05-04 Thread Lonnie Princehouse
> If you want to compare partial keys, often the simplest approach is to > use tuples as keys, with the elements of the tuple being the "parts" of > the key. Python's standard tuple comparison mechanism takes care of the > rest. Right, but suppose it's expensive to generate each part of the key -

Re: python and glut

2005-05-04 Thread Lonnie Princehouse
See if you can run `glxgears`, and read the output of `glxinfo`. If neither of those work, you will probably have better luck on a debian or XFree86/xorg forum than on c.l.py -- http://mail.python.org/mailman/listinfo/python-list

Debugging C extensions on Gentoo

2005-05-04 Thread Lonnie Princehouse
I've spent the last couple of hours trying to figure out how to set breakpoints in Python C extensions under gdb 6.2 using Gentoo Linux, and finally figured it out. So for posterity (aka Google), here's the trick: If GDB is giving you the message "Unable to find dynamic linker breakpoint funct

Re: Sorting an Edge List

2005-04-29 Thread Lonnie Princehouse
Sort demands a unique ordering, which isn't present in your case. You're constructing an Eulerian path. See Fleury's algorithm: http://en.wikipedia.org/wiki/Eulerian_path -- http://mail.python.org/mailman/listinfo/python-list

Re: module exports a property instead of a class -- Evil?

2005-04-29 Thread Lonnie Princehouse
The property factory is nice, but have you considered subclassing property? class Mode(property): def __init__(self, *vals): if [v for v in vals if not isinstance(v,str)]: raise ValueError, 'Mode values must be strings' else: self.values = list(vals) property.__init__(sel

Re: how can I sort a bunch of lists over multiple fields?

2005-04-29 Thread Lonnie Princehouse
key and cmp are equivalent for non-trivial cases (defined below), and for trivial cases the performance will be a trade-off between more function calls with cmp versus more memory use with key. Granted, for the smallish lists that the majority of Python sorts are done on, key is probably the bette

Re: how can I sort a bunch of lists over multiple fields?

2005-04-28 Thread Lonnie Princehouse
> Likewise, the above is basically just an inefficient way of writing: > > def date_key(book): > return book.data > > def author_and_date_key(book): > return (author_key(book), date_key(book)) It's certainly more elegant, but I wanted to talk about the mechanics of comparison functions =)

Re: how can I sort a bunch of lists over multiple fields?

2005-04-28 Thread Lonnie Princehouse
> I'd be just such a newbie; I don't understand why it would matter if I > left the book instance referencing itself It's just kind of sloppy and unnecessary to have self.self > firstly, I am trying hard to figure out how to create a new file with > the list rather than print to standard out

Re: how can I sort a bunch of lists over multiple fields?

2005-04-27 Thread Lonnie Princehouse
Might as well make a class for Book instead of dealing with buckets of lists... class Book(object): def __init__(self, title, author, publisher, isbn, date):# add more fields according to CSV self.__dict__.update(locals()) # lazy! def __repr__(self): return '<"%s" by %

Re: Pythonic way to do static local variables?

2005-04-26 Thread Lonnie Princehouse
A quick, hackish way to keep a static variable is to declare it as a parameter and give it a default value. The parameter list is evaluated when the function is compiled, not when it is called. The underscores are added as per convention to indicate that the variable is special/private. Example

Re: Pythonic way to do static local variables?

2005-04-26 Thread Lonnie Princehouse
A quick, hackish way to keep a static variable is to declare it as a parameter and give it a default value. The parameter list is evaluated when the function is compiled, not when it is called. The underscores are added as per convention to indicate that the variable is special/private. Example

Re: Injecting code into a function

2005-04-26 Thread Lonnie Princehouse
> I think that Your trace_returns function is actually a global trace > that returns itself and does not handle the 'call' event. By returning itself, the global trace also becomes the local trace. The code in bdb.py does the same thing--- self.trace_dispatch is set as the global trace, and retur

Re: Injecting code into a function

2005-04-25 Thread Lonnie Princehouse
I don't know of a way to get the current global trace function. This could certainly cause trouble if you're trying to be compatible with other packages that want to use their own trace functions (like psyco, or debuggers). Does anyone know how to get the global trace? On the other hand, the lo

  1   2   >