[Pythonmac-SIG] Using Python with Terminal

Truls A. Tangstad kerfue+pythonmac-sig at herocamp.org
Wed Mar 9 22:36:35 CET 2005


On Wed, Mar 09, 2005 at 04:13:25PM -0500, Nick Matsakis wrote:
> 
> Is there a simple way to use python with the Mac Terminal so that the
> arrow keys will allow you to execute previously executed statements?
> I'm using python 2.3.0 on 10.3.

Still haven't solved that one myself, but I usually interact with
python interactively through emacs, or an xterm.

> Also, a random Python question.  I'd like to get an arbitrary element from
> a sets.Set _without_ mutating the sets.  The most concise way I could find
> is this:
> 
> for item in someset: break
> 
> Which will assign item to an arbitrary element in someset.  This
> expression really annoys me, though. Is there a better way?

Well.. for an uncertain definition of "better", the following is a
possibility:

item = list(someset)[0]

# a more random choice
from random import choice
item = choice(list(someset))

-- 
Truls A. Tangstad - <kerfue+pythonmac-sig at h e r o c a m p.org>


More information about the Pythonmac-SIG mailing list