Re: Where to put the error handing test?

2009-11-24 Thread Paul Miller
On Mon, 23 Nov 2009 22:27:24 -0800, alex23 wrote: As a very rough example: def g(x): try: assert isinstance(x, int) except AssertionError: raise TypeError, excepted int, got %s % type(x) # ... function code goes here def f(x):

Any elegant way to construct the complete $k$-partite graph in Python?

2009-11-23 Thread Paul Miller
I was wondering if there were any neat tools (like for instance, something from itertools) that would help me write the following function more elegantly. The return value should, of course, be the complete $k$- partite graph $K_{n_1, n_2, \dots, n_k}$: def completeGraph (*ns): '''

Re: Any elegant way to construct the complete $k$-partite graph in Python?

2009-11-23 Thread Paul Miller
On Mon, 23 Nov 2009 19:57:05 -0800, Richard Thomas wrote: Not sure exactly how you're representing graphs, this seems like the simplest way of listing the edges. def complete_partite(*sizes): total = sum(sizes) nodes, edges = range(total), [] for group in xrange(len(sizes)):

Re: adding a directory to sys.path

2009-11-23 Thread Paul Miller
On Mon, 23 Nov 2009 12:02:36 -0500, John Guenther wrote: This is Mac related. I am running snow leopard. I am using Python 2.6.3. I had a lot of difficulty figuring out how to add a directory to sys.path that would be there every time I launched Idle. [...] For a comprehensive discussion of

Re: Do this as a list comprehension?

2008-06-07 Thread Paul Miller
On Fri, 06 Jun 2008 18:01:45 -0700, Mensanator wrote: What happens if your iterables aren't the same length? I chose not to consider that case, since they were the same length in the original post. Based on the variable names, it seemed reasonable that there would always be a 1-to-1

Re: definition of a highlevel language?

2008-05-29 Thread Paul Miller
On Mon, 26 May 2008 15:49:33 -0400, Dan Upton wrote: On Mon, May 26, 2008 at 3:22 PM, [EMAIL PROTECTED] wrote: I don't know if it would necessarily look like the CPython VM, except for the decode stage (this being said without any knowledge of the CPython implementation, but with more than

Re: Tkinter = Rodney Dangerfield?

2008-05-29 Thread Paul Miller
On Sun, 17 Feb 2008 11:35:35 -0800, MartinRinehart wrote: Tkinter gets no respect. But IDLE's a Tkinter-based app and every example I've Googled up shows Tkinter as needing about half as much code as wx to do the same job. I'm beginning to Tkinter up my language application. Am I making a big

Literate programs in Python

2008-05-13 Thread Paul Miller
Does anyone know of any (preferably largish) examples of literate programs written using Python? Alternatively, does anyone know of any literate programming tools which support Python well? (I am aware of Leo and I've been to literateprogramming.com, but any additional pointers would be much

best way of dealing with currency?

2007-10-16 Thread Paul Miller
I'm looking at doing some currency calculations in some Python code integrated with a C++ application. I want to be able to come up with the same values I get in an Excel spreadsheet. I've been poking around for a couple of days and haven't come across a definitive method for dealing with

Semantics of thread.error

2007-08-05 Thread Paul Miller
In the language documentation, all that is said about thread.error is that it's raised on thread-specific errors. Is there anywhere a list of conditions which will cause thread.error to be raised? (I mean, other than the thread library C source, of course.) Thanks! Paul --

Bastion/rexec use cases?

2007-05-07 Thread Paul Miller
Bastion and rexec have been deprecated since Python 2.2, so it seems we (the Python community) have gotten along well enough without them. Have these modules not been reimplemented because: a) There are no valid use cases for them. b) Doing so would be difficult and prone to breakage as new

Numeric import_array() problem - OS X 10.4

2006-07-05 Thread Paul Miller
I had some code that used to work that now doesn't. It's an embedded Python interpreter that uses numpy internally. The code calls import_array(), which now fails (and generates a ImportError: No module named _numpy error). This is on the latest OS X 10.4 release. I have Numeric installed in

Re: Numeric import_array() problem - OS X 10.4

2006-07-05 Thread Paul Miller
Paul Miller wrote: I had some code that used to work that now doesn't. It's an embedded Python interpreter that uses numpy internally. The code calls import_array(), which now fails (and generates a ImportError: No module named _numpy error). Nevermind - user error. A recent OS X update

Re: MacPython 2.2 on Mac OS X 10.3.8 - configurePython error

2005-08-26 Thread Paul Miller
Robert Kern wrote: Paul Miller wrote: I have a user who is is having trouble getting MacPython on his OS X 10.3.8 system. When he runs ConfigurePythonCarbon, he gets this error: [terminated] 'import site' failed; use -v for traceback traceback )most recent call last): File

Re: MacPython 2.2 on Mac OS X 10.3.8 - configurePython error

2005-08-26 Thread Paul Miller
Robert Kern wrote: Paul Miller wrote: Robert Kern wrote: MacPython 2.2 has been long abandoned. The official OS X binary for Python 2.4.1 can be found here: http://www.python.org/ftp/python/2.4.1/MacPython-OSX-2.4.1-1.dmg I realize that, but I have an application that is linked

MacPython 2.2 on Mac OS X 10.3.8 - configurePython error

2005-08-25 Thread Paul Miller
I have a user who is is having trouble getting MacPython on his OS X 10.3.8 system. When he runs ConfigurePythonCarbon, he gets this error: [terminated] 'import site' failed; use -v for traceback traceback )most recent call last): File Moes:SWdev:Jack:Python2.2:Mac:script:configurePython.py,

anonymous functions/expressions without lambda?

2005-04-28 Thread Paul Miller
I see lambda is going away, so I want to use something that will be around for awhile. All I want to do is provide an inline function as an argument to another function. For example, let's say I have a function which binds a key to a function call. I want to do something simple in this

Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Paul Miller
Michael Hoffman wrote: That's what lambda does. But it's going away, you'll have to use def when it does, unless the language designers come up with something better. Yeah, I'm using lamda now it works nicely/cleanly. If a lot of the bindings are actually setting variables, you could do

Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Paul Miller
Michael Hoffman wrote: Dave Benjamin wrote: I think you meant to write something like this: def attrsetter(obj, name, value): def _return_func(): return setattr(obj, name, value) return _return_func Sure did. Sorry. You guys have been very helpful! While on the subject, is there

embedding an interactive console

2005-04-28 Thread Paul Miller
I did this YEARS ago with Python 1.5, and I recall it being slightly painful. I have an embedded Python interpreter and I want to provide an interactive console (implemented in my GUI application with a Qt TextEdit widget). I can handle the GUI part of it, but I'm wondering what the latest

Re: anonymous functions/expressions without lambda?

2005-04-28 Thread Paul Miller
Michael Hoffman wrote: Paul Miller wrote: While on the subject, is there an equivalent for methodcaller? ie. if I want to bind a function which calls a specific method of an object with a specific parameter? def funccaller(func, *args, **kwargs): def _return_func(): return func(*args

Re: embedding an interactive console

2005-04-28 Thread Paul Miller
Paul Miller wrote: I note the documentation for InteractiveConsole, which is implemented in Python. Is there any example code for using this from within C/C++ code to emulate the command-line interpreter inside a GUI app? I've gotten my text edit widget to send InteractiveConsole strings to run