makepy crashing

2005-01-18 Thread markscottwright
Has anyone sucessfully run makepy and Microsoft Word Object Library
(9.0)?  Mine crashes under XP Pro and Python 2.4.

It only seems to be word that has the problem, though.

I get a dialog that says that pythonwin.exe has crashed:
AppName: pythonwin.exe   AppVer: 0.0.0.0 ModName: ntdll.dll
ModVer: 5.1.2600.1217Offset: 96f9

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


iterative lambda construction

2005-02-21 Thread markscottwright
Just for the hell of it, I've been going through the old Scheme-based
textbook "Structure and Interpretation of Computer Programs" and seeing
what I can and can't do with python.  I'm trying to create a function
that returns the function (not the results of the function, but a
function object) that results from applying function f to it's (single)
argument N times.  For example, if you have "def sq(x): return x*x",
then repeated(sq, 2)(2) = 16, repeated(sq, 3)(2) = 256, etc.

I can do it recursively, like this:

def repeated(f, count):
   if count == 1:
   return f
   else:
   return lambda x: f(repeated(f, count - 1)(x)

But when I try to do it iteratively, it just hangs when I try to
evaluate the results (for count > 1):

def repeated2(f, count):
newfun = f
for i in range(count-1):
newfun = lambda x: newfun(f(x))
return newfun

For the life of me, I can't figure out why.  It seems like for count =
2, for example, the results from repeated2 should be lambda x: f(f(x)),
but it doesn't seem to be.

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


How to I restart an interactive session?

2005-03-18 Thread markscottwright
I'm trying to cobble together an IDLE equivalent using pyshell and VIM
(My idea is just to pipe exec file commands from VIM to pyshell via a
socket or something).  The one feature that IDLE has that I would
really like but can't seem to duplicate is the "Restart Shell" command.
 Delving through the IDLE code, it looks like IDLE kills and restarts
its InteractiveInterpreter-derived class to do this.  Is this really
necessary?  If I just take __main__.__dict__ and strip out everything
since a start point, haven't I restored the interpreter to a virgin
state?

(Of course, assuming that there are no threads running, no
c-code-invoked junk lying around, etc).

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


Re: How to I restart an interactive session?

2005-03-18 Thread markscottwright
But, by deleting their namespace entries haven't I effectively unloaded
them?  In other words, from the point of the interpreter, isn't the
state at point A and point B the same?

--- point A:
  import os
  del __main__.__dict__['os']
--- point B

I guess my question boils down to, is the state of the python
interpreter kept anywhere other than the __main__ namespace?  Obviously
the answer is yes - there's the current working directory and any
running threads.  I think I'm willing to live with those (yeah, I know,
those are the words of a man who is going to spend time chasing obscure
side-effects...)

But are there other things I'm missing?  Is my whole plan misguided
from the beginning?

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


Re: Abelson and Python

2006-11-22 Thread markscottwright

[EMAIL PROTECTED] wrote:
> While studying the SICP video lectures I have to twist my mind some to
> completely understand the lessons. I implement the programs shown there
> in both Python and Scheme, and I find the Python implementations
> simpler to write (but it's not a fair comparison because I know very
> little Scheme still).
>
> Now some things are changing:
> http://lambda-the-ultimate.org/node/1840
>
> >The MIT is going to change its curriculum structure that was famous for 
> >teaching Scheme in introductory courses. One force behind the reform is no 
> >one else than Harold Abelson, famous for his marvelous Scheme opus SICP.<
> >The first four weeks of C1 will be a lot like the first four weeks of 6.001, 
> >Abelson said. The difference is that programming will be done in Python and 
> >not Scheme.<

I am shocked by this.  I love Python as much as the next guy, but I
just don't see how SICP can be done in Python.  Chapters 1-3, sure.
But chapter 4 has you writing a Scheme interpreter in Scheme, and
chapter 5 has you writing a Scheme compiler in Scheme.  I don't see how
that can be done in Python - certainly not in one chapter of a
textbook.  Am I to believe that students will be writing a Python
metacircular evaluator?  If it were that easy, the PyPy guys would be
done by now.

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


Re: Abelson and Python

2006-11-23 Thread markscottwright
Fredrik Lundh wrote:
> markscottwright wrote:
>
>  > If it were that easy, the PyPy guys would be done by now.
>
> if the PyPy guys had focused on writing a Python interpreter in Python,
> they'd been done by now.
>
> 

Isn't that the point of PyPy?  It's what their mission statement says
(http://codespeak.net/pypy/dist/pypy/doc/architecture.html#mission-statement):

"PyPy is an implementation of the Python programming language written
in Python itself, flexible and easy to experiment with."

This is something that is amazingly easy to do in scheme, since the
language is so simple, but is typically pretty difficult to do in other
languages.  I remember being blown away by how much I knew after
reaching the end of SICP - I wanted to go out and write my own scheme
compiler (and given the proliferation of scheme implementations, a lot
of other people must have felt the same way).  I don't remember getting
to the end of a book on python and thinking, "that's easy.  I could do
that!"

That said, I see now that the course we're talking about isn't the same
as the old 6.001 course, and presumably has different pedagogical goals.

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


Is there a standard binary search with overridable comparisons?

2008-06-17 Thread markscottwright
I've got an ordered list of MyClasses that I want to be able to do
binary searches on, but against a tuple.  MyClass has valid
__lt__(self, rhs) and __eq__(self, rhs) member functions that work
when rhs is a tuple.

This works:
l = [MyClass(..), MyClass(..), ...]
l.find((a,b))

But this doesn't:
bisect.bisect(l, (a,b))

I'm assuming this is because inside bisect, it does 'key < list[x]'
rather than 'list[x] < key', so it's the tuple's __lt__ that is
called, rather than MyClass's tuple.

Is there a way around this?  Can I monkeypatch a new __lt__ into the
tuple class?

Here's some sample code that demonstrates the problem (it uses ints
rather than tuples, but the

import bisect
class MyC:
def __init__(self, v):
self.v = v

def __lt__(self, rhs):
return self.v < rhs

# cant search for int in a list of MyC's
l = sorted([MyC(x) for x in range(1000)])
bisect.bisect(l, 40)
1001 # AKA not found

# but, I can search for MyC in a list of ints
l = sorted(range(1000))
bisect.bisect(l, MyC(40))
41
--
http://mail.python.org/mailman/listinfo/python-list


How do I convert an iterator over bytes into a str?

2009-08-18 Thread markscottwright
This does what I expected:
In [6]: list(iter([1,2,3,4,5]))
Out[6]: [1, 2, 3, 4, 5]

But this appears to be doing a __repr__ rather than making me a nice
string:
   In [7]: str(iter("four score and seven years ago"))
   Out[7]: ''

What's the correct way to turn an iterator over bytes into a string?
This works, but, ewww:
In [8]: "".join(iter("four score and seven years ago"))
Out[8]: 'four score and seven years ago'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I convert an iterator over bytes into a str?

2009-08-19 Thread markscottwright
On Aug 18, 6:52 pm, "Jan Kaliszewski"  wrote:
> 19-08-2009 o 00:24:20 markscottwright  wrote:
>
> > What's the correct way to turn an iterator over bytes into a string?
> > This works, but, ewww:
> >     In [8]: "".join(iter("four score and seven years ago"))
> >     Out[8]: 'four score and seven years ago'
>
> But it is the correct way (and even recommended over s=s+t or s+=t, when
> applicable
> -- see:  
> http://docs.python.org/library/stdtypes.html#sequence-types-str-unico...).
>
> Cheers,
> *j
>
> --
> Jan Kaliszewski (zuo) 

Thanks Jan (and all other responders).  I suppose I shouldn't be
surprised - it's a known wart (http://wiki.python.org/moin/
PythonWarts), but it just looks so darn wrong.  It is, as you point
out, much faster than "better looking" alternatives, though -
http://www.skymind.com/~ocrow/python_string/
-- 
http://mail.python.org/mailman/listinfo/python-list