Re: [Pythonmac-SIG] History of Python in MacOSX

2005-01-29 Thread Just van Rossum
Robert White wrote:

> I started with Jaguar, MacOSX 10.2, where Python was built as a 
> framework.

The Python that shipped with 10.2 was not a framework build, but an
"ordinary" static unix build, or whatever the correct term for that is.

> I am just curious.  Was Python included with 10.1 or 10.0?  
> If so, were they framework builds as well?

It was not.

Just
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] History of Python in MacOSX

2005-01-29 Thread Bob Ippolito
On Jan 29, 2005, at 4:28, Just van Rossum wrote:
Robert White wrote:
I started with Jaguar, MacOSX 10.2, where Python was built as a
framework.
The Python that shipped with 10.2 was not a framework build, but an
"ordinary" static unix build, or whatever the correct term for that is.
Mac OS X 10.2 shipped with Python 2.2.0, which was rife with bugs (both 
cross-platform and Mac specific bugs).  A shared library was not 
available, so this Python could not be embedded in other software.  
Thus, application bundles that bootstrapped with this Python needed to 
use a shell script or equivalent that did an execve(...) call to 
/usr/bin/python.  Additionally, the config/Makefile for this Python had 
some compiler flags related to x86 cross-compilation that Apple 
neglected to remove from their production build, thus it was necessary 
to sudo vi this file or mangle distutils a bit at runtime from setup.py 
in order to build extensions at all.

Not terribly long after Mac OS X 10.3 and Python 2.3.0 came out, people 
stopped supporting this Python 2.2.0, because it was horrible.

-bob
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] Trouble getting TK to work

2005-01-29 Thread Dave Kanter
Forgive me if this question has been asked 100 times.  I tried reading 
through past archives, honest I did.

I'm having some trouble with Python and TK, but I'm not sure how to proceed. 
 This is what I did:

I'm using the version of Python that came with OSX -- version 2.3.  I also 
downloaded TclTkAquaBl - 8.4.9.0 and ran the installer.Then I fired up 
Python, and typed:

from Tkinter import *
and then
root = Tk()
Which were commands I got from the Python book I'm working out of.  This is 
what happened:

from Tkinter import *
Traceback (most recent call last):
 File "", line 1, in ?
 File "/sw/lib/python2.3/lib-tk/Tkinter.py", line 3, in ?
   Tkinter provides classes which allow the display, positioning and
NameError: name 'Tk' is not defined
root = Tk()
Traceback (most recent call last):
 File "", line 1, in ?
NameError: name 'Tk' is not defined

It seems to me it's an improper path configuration, but for the life of me I 
can't figure out how to get it straight.  Any help would be much 
appreciated.

Dave.
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] Mutating Row in a matrix

2005-01-29 Thread Kirk Durston
Title: Mutating Row in a matrix



It will be obvious that I am a newbie here when you see my question, but here goes. I am writing my first program, and have encountered a problem which I’ve been able to reproduce in the short program below. Basically, I select a row (B) from a matrix and I want to keep B constant. Then I create a new matrix by copying the old, and mutate the new matrix. I then want to substitute the unmutated row B  into the mutated new matrix.

Problem: B changes, as you can see when you run the short program below. So does the original matrix, although I don’t care about that.

Question: Why does the list B change when I don’t work on it? I want to understand this.

Question #2: A solution would be to convert the list B into a tuple and then reconvert the tuple back into a list after the new matrix has been mutated and insert it, but I still want to understand why a list would change when I’m haven’t done anything to it.

Here’s a small program that reproduces the problem. When B changes depends upon the value you set for ‘e’

import random
A = [[1,1,1,1,1], [2,2,2,2,2],[3,3,3,3,3],[4,4,4,4,4]]
e = 2
B = A[e]
Columns = 4
Rows = 4
NewMatrix = A
MutationRate = .    #Mutation of NewMatrix
s = 0
while s
print "B is", B
h=0
while h
x=random.random()
if x<=MutationRate:
NewMatrix[s][h] = abs(NewMatrix[s][h] - 9)
if h == Columns - 1: break
h += 1
if s ==Rows -1: break
s += 1
print 'B is', B
print A
print "***"



___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] Mutating Row in a matrix

2005-01-29 Thread Bob Ippolito
On Jan 29, 2005, at 1:29 PM, Kirk Durston wrote:
It will be obvious that I am a newbie here when you see my question, 
but here goes. I am writing my first program, and have encountered a 
problem which I’ve been able to reproduce in the short program below. 
Basically, I select a row (B) from a matrix and I want to keep B 
constant. Then I create a new matrix by copying the old, and mutate 
the new matrix. I then want to substitute the unmutated row B  into 
the mutated new matrix.

Problem: B changes, as you can see when you run the short program 
below. So does the original matrix, although I don’t care about that.

Question: Why does the list B change when I don’t work on it? I want 
to understand this.

Question #2: A solution would be to convert the list B into a tuple 
and then reconvert the tuple back into a list after the new matrix has 
been mutated and insert it, but I still want to understand why a list 
would change when I’m haven’t done anything to it.
What you're missing here is that everything in Python is an object, and 
variables are just *references* to objects.  When you say ``a = b[0]``, 
``a`` is a reference to ``b[0]``.  If ``b[0]`` is some mutable object, 
like a list or a dict, you're simply referencing it.  In this case, 
changing ``a`` would "also change" ``b[0]`` because they ``a`` and 
``b[0]`` are references to the *same object*.

You should read this: 
http://starship.python.net/crew/mwh/hacks/objectthink.html

There is no need to convert a list to a tuple and back again.  Two 
simple ways to make a shallow copy of a list are ``list(anotherList)`` 
or ``anotherList[:]``.  You should also read the documentation for the 
``copy`` module, whether or not you end up using it in your 
implementation.

-bob
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] How do I send appleevents to an external program

2005-01-29 Thread Joachim MÃ¥rtensson
Hello everyone.
I am trying to figure out how to send appleevents to an external 
program. What I want to accomplish is to open a text document in a 
editor that supports the external editor protocol as described here 
http://www.codingmonkeys.de/techpubs/externaleditor/pbxexternaleditor.html.
Here is my code so far, What am I doing wrong? _filePath is the path to 
the file and _lnnum is the line number where I want to place the caret. 
I am using PyObjc but no api in cocoa seems to exist so I use various 
other modules.

def openInExternalEditor(self, _filePath, _lnnum):
   import aetools, struct
  
   editor = aetools.TalkTo('TxMt', 0) # TxMt = textmate a texteditor
   keyDirectObject = ''
   keyAEPosition = 'sopk'
   _code = 'aeve'# kCoreEventClass
   _subcode = 'odoc'  # kAEOpenDocuments
   SelectionRange=struct.pack('hh', 0, int(_lnnum), 0,0,0,0)
   _arguments = {}
   _arguments[keyDirectObject] = _filePath
   _arguments[keyAEPosition] = SelectionRange
   
   _attributes = {}
   editor.send(_code, _subcode, _arguments, _attributes)

Thanks in advance
Joachim Mårtensson
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] How do I send appleevents to an external program

2005-01-29 Thread Bob Ippolito
On Jan 29, 2005, at 19:40, Joachim Mårtensson wrote:
Hello everyone.
I am trying to figure out how to send appleevents to an external  
program. What I want to accomplish is to open a text document in a  
editor that supports the external editor protocol as described here  
http://www.codingmonkeys.de/techpubs/externaleditor/ 
pbxexternaleditor.html.
Here is my code so far, What am I doing wrong? _filePath is the path  
to the file and _lnnum is the line number where I want to place the  
caret. I am using PyObjc but no api in cocoa seems to exist so I use  
various other modules.
PyObjC can use AppleScript with the NSAppleScript class  
.  However, the best way to  
send Apple Events from Python is probably appscript  
.  The  
standard library support for Apple Events is very... raw, so I wouldn't  
recommend that approach to anyone :)

-bob
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] How do I send appleevents to an external program

2005-01-29 Thread Joachim MÃ¥rtensson
Bob Ippolito wrote:
On Jan 29, 2005, at 19:40, Joachim Mårtensson wrote:
Hello everyone.
I am trying to figure out how to send appleevents to an external  
program. What I want to accomplish is to open a text document in a  
editor that supports the external editor protocol as described here  
http://www.codingmonkeys.de/techpubs/externaleditor/ 
pbxexternaleditor.html.
Here is my code so far, What am I doing wrong? _filePath is the path  
to the file and _lnnum is the line number where I want to place the  
caret. I am using PyObjc but no api in cocoa seems to exist so I use  
various other modules.

PyObjC can use AppleScript with the NSAppleScript class  
.  However, the best way to  
send Apple Events from Python is probably appscript  
.  The  
standard library support for Apple Events is very... raw, so I 
wouldn't  recommend that approach to anyone :)

-bob
Ok thanks, I downloaded the aem module from the page you linked. 
Everything works fine except for the placing of the caret.
I have tried various ways to get this c-structure to work.
struct SelectionRange
{
short unused1; // 0 (not used)
short lineNum; // line to select (<0 to specify range)
long startRange; // start of selection range (if line < 0)
long endRange; // end of selection range (if line < 0)
long unused2; // 0 (not used)
long theDate; // modification date/time
};

This is what I have come up with so far. What is the proper way of 
passing the struct?

def openInExternalEditor(self, _filePath, _lnnum):
  from aem.send import Application
  import struct
  from Carbon.File import FSSpec
  SelectionRange=struct.pack('hh', 0, int(_lnnum), 0,0,0,0)
  
Application('/Applications/TextMate.app').event('aevt','odoc',{'':FSSpec(_filePath),'sopk':`SelectionRange`}).send()

___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] Trouble getting TK to work

2005-01-29 Thread eichin
>  File "/sw/lib/python2.3/lib-tk/Tkinter.py", line 3, in ?

/sw means you're getting something out of Fink, which may be your
problem -- the fink install hacks a path set into your account's
dotfiles somewhere, so you may only *think* you're getting the one
that comes with osx... Note the difference:

$ python
Python 2.3 (#1, Sep 13 2003, 00:49:11) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
$ /sw/bin/python
Python 2.3.3 (#1, Aug 23 2004, 20:06:57) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1640)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Also if you import sys and print sys.path in either case you'll find
*very* different sets of places that they look for installed things...

(It also looks from the traceback that you're missing a first line of
/sw/lib/python2.3/lib-tk/Tkinter.py, but that's locally strange...)
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig