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", line 11 
, in ?
Import error: No module named os


I have had no trouble on my system (same version).

What can cause this?

-Paul

-- 
http://mail.python.org/mailman/listinfo/python-list


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 "Moes:SWdev:Jack:Python2.2:Mac:script:configurePython.py", line 11 
>>, in ?
>>Import error: No module named os
>>
>>
>>I have had no trouble on my system (same version).
>>
>>What can cause this?
> 
> 
> os.py got deleted from its home, probably. I doubt anyone is going to
> help fix the problem though. 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 with MacPython 
2.2. I can't just drop 2.4 in.

He claims the only thing that has changed is his preferences were wiped 
out. There must be some solution for what is probably a not too uncommon 
problem.

> 

-- 
http://mail.python.org/mailman/listinfo/python-list


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 with MacPython 
>>2.2. I can't just drop 2.4 in.
> 
> 
> Is this an application that you've written? If so, then I realize that
> you can't just drop 2.4 in painlessly, but you really should consider
> upgrading your software to use a newer Python. No one is going to
> support MacPython 2.2.

Yes, this is an app I have written. I could take the time to rebuild it 
with the latest Python, yes.

However, the simpler solution seemed to be to try to figure out why it 
won't reconfigure itself. I have OS X 10.3.8 and a clean install works 
perfectly fine. Surely someone somewhere has used MacPython 2.2 on OS X 
10.3.8 and heard of a similar issue, with ConfigurePythonCarbon not 
working after preferences were destroyed.

This is why I asked here.

>>He claims the only thing that has changed is his preferences were wiped 
>>out. There must be some solution for what is probably a not too uncommon 
>>problem.
> 
> It *is* uncommon. Judging from the traffic on the Pythonmac-SIG,
> virtually no one is using MacPython 2.2 anymore. You can ask for help on
> there, but I don't think you'll fare any better.

Perhaps I am the only developer with a legacy application he's trying to 
support. But I doubt it.

-- 
http://mail.python.org/mailman/listinfo/python-list


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 function call, and I have 
a lot of bindings, so I don't want to have a ton of tiny little 
functions scattered around:

def setVarTo1():
foo.var = 1
def setVarTo2():
foo.var = 2
bind('a', setVarTo1)
bind('b', setVarTo2)
Instead, I'd like to do something like this:
bind('a', foo.var = 1)
bind('b', foo.var = 2)
What's the recommended way to do something like this?
Note that the bind function is implemented in "C", and I am embedding 
the interpreter.

--
http://mail.python.org/mailman/listinfo/python-list


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 
something like this:

def attrsetter(obj, name, 1):
def _return_func(value):
return setattr(obj, name, value)
return _return_func
bind('a', attrsetter(foo, "var", 1))
bind('a', attrsetter(foo, "var", 2))
Ah, perfect. Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


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 an equivalent for "methodcaller"?
ie. if I want to bind a function which calls a specific method of an 
object with a specific parameter?

--
http://mail.python.org/mailman/listinfo/python-list


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 Python method of implementing this is.

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?

--
http://mail.python.org/mailman/listinfo/python-list


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, **kwargs)
return _return_func
...
And this time I actually tested it, and it works! ;)
Wow! Amazing. Yer right, it works!
Man, I LOVE this language.
--
http://mail.python.org/mailman/listinfo/python-list


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 and can see the results.

But I'm not getting a >>> prompt consistently.
I'd love to see some sample code from anyone who is using this with an 
embedded interpreter.

--
http://mail.python.org/mailman/listinfo/python-list


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 the 
Python site-packages directory, and it loads and works properly from a 
normal Python command prompt.

I also just noticed that other modules from the standard Python library 
can't be loaded from within my embedded interpreter. It does find 
scripts I have in my application sub-directory, which I reference by 
adding a path to sys.path.

I modified my startup script to print out sys.path, and a bunch of paths 
(including the site-packages location) are there.

Has something changed with Apple's Python implementation that changes 
the way standard library modules are imported from embedded interpreters?

-- 
http://mail.python.org/mailman/listinfo/python-list


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 changed the paths Python 
looks in for site libraries.

I love it when Apple silently decides to break stuff. I can spend hours 
trying to track it all down instead of getting work done - but it's fun 
because I'm using a shiny Mac!

-- 
http://mail.python.org/mailman/listinfo/python-list


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 features
are introduced into the language.
c) Nobody has any idea how to do it.
d) Nobody cares.
e) Guido thinks it's a bad idea.

or, some combination of these?

-- 
http://mail.python.org/mailman/listinfo/python-list


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

-- 
http://mail.python.org/mailman/listinfo/python-list


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 currency in a precise manner.

What do I need to do? Use rationals? Very high-precision floating-point? 
  mxNumber? Or something else?

Thanks for any and all input!

-- 
http://mail.python.org/mailman/listinfo/python-list


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 appreciated!)

Thanks,

Paul
--
http://mail.python.org/mailman/listinfo/python-list


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 I ever thought I'd know about
> processor architecture/microarchitecture)

Out of curiosity, do you know how easy it would be to make a Python chip 
using FPGAs?  I have little to no hardware knowledge, but it sounds like 
a fun project in any case.  Even if it's not likely to have blazing 
performance, it'd be cool to load Python bytecode directly into 
memory. :-)

-- 
code.py: a blog about Python.  http://pythonista.wordpress.com
** Posted from http://www.teranews.com **
--
http://mail.python.org/mailman/listinfo/python-list


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 mistake?

I like Tkinter quite a bit.  I think it's relatively intuitive, and I 
like the Canvas and Text widgets a lot.

You might check out _Thinking in Tkinter_ at http://www.ferg.org/
thinking_in_tkinter/index.html .  

-- 
code.py: a blog about Python.  http://pythonista.wordpress.com
** Posted from http://www.teranews.com **
--
http://mail.python.org/mailman/listinfo/python-list


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 correspondence between elements of each 
list.  However, if you do

score_costs = [(base_scores[i], score_costs[i]) for i in range (min (len 
(base_scores), len (score_costs))]

then you get exactly what you would get using zip.  That's one heck of a 
long line, though, hence my earlier comment:

>> But, I'd rather just use zip. :-)
> 
> And with zip() you won't get an error, but it won't be correct, either.

If it doing what zip() does makes sense, then just use zip().  Otherwise, 
check for the case where the iterables are of different length, and do 
the appropriate thing (raise an error, pad the shorter one, whatever).

-- 
code.py: a blog about Python.  http://pythonista.wordpress.com
** Posted from http://www.teranews.com **
--
http://mail.python.org/mailman/listinfo/python-list


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):
'''
Returns the complete graph $K_{n_1, n_2, \dots, n_k}$ when passed
the sequence \code {n_1, n_2, \dots, n_k}.
'''
if len (ns) == 1:
return completeGraph ( * ([1] * ns[0]) )
n = sum (ns)
vertices = range (n)
partition_indices = [sum (ns[:i]) for i in range (len (ns))] 
partite_sets = [vertices[partition_indices[i]:partition_indices[i+1]] 
\
for i in range (len (partition_indices) - 1)]
partite_sets.append (vertices[partition_indices [-1]:] )

edges = []
for i in range (len (partite_sets)):
for j in range (i + 1, len (partite_sets)):
edges.extend ([ (u, v) for u in partite_sets [i] for v in \
   partite_sets [j] ])

return graph.Graph (vertices = vertices, edges = edges)

Many thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


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)):
> low = sum(sizes[:group-1])
> high = sum(sizes[:group])
> edges.extend((i, j) for i in xrange(low, high)
> for j in xrange(high, total))
> return nodes, edges

Thanks!  I think this is what I was looking for (unless the collective 
wisdom of c.l.py can come up with something *even more* elegant). :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


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 how to modify sys.path, see 

http://docs.python.org/install/index.html#modifying-python-s-search-path

If you really just need to modify sys.path for one particular user, what 
I would do is add the line

export PYTHONSTARTUP="/home/my_user/python/startup.py"

to my .bashrc.  Then, in the file /home/my_user/python/startup.py, 
include the following code:

import sys

sys.path.append ("/home/my_user/some_dir")

This will add the directory /home/my_user/some_dir to sys.path every time 
you start up Python.  

The reason I like using PYTHONSTARTUP is that you can do other sorts of 
customizations in that file, as well.  For example, I hate not having any 
way to clear the screen when I'm typing at the Python prompt, so I added 
this code to my $PYTHONSTARTUP file:

import os

def clear():
os.system ('clear')

Hope that all helps!
-- 
http://mail.python.org/mailman/listinfo/python-list


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):
> try:
> g(x)
> except TypeError:
> # handle the problem here
> # ... function code goes here

I know you say this is a "very rough" example, but, generally you don't 
want to do this kind of "type checking" with isinstance.  Rather, it's 
better to just simply manipulate x as if it were an integer and rely on 
Python to check to see if x supports the operations you're trying to do 
with it.  For instance, say we have

def g(x):
return x * x

def f(x):
return g(x) + 2

If you try to pass any value to either of these functions that doesn't 
support the required operations, Python itself will complain with a 
TypeError.  Since the interpreter needs to do this check *anyway*, 
there's no real sense in repeating it manually by checking isinstance.

-- 
http://mail.python.org/mailman/listinfo/python-list