ANN: Urwid 0.9.8 - Console UI Library

2007-03-26 Thread Ian Ward
Announcing Urwid 0.9.8
--

Urwid home page:
   http://excess.org/urwid/

Tarball:
   http://excess.org/urwid/urwid-0.9.8.tar.gz


About this release:
===

This release improves Urwid's performance by 70% to 450% (reducing 
running time by 41% to 82%)[1] for some benchmarks[2].  New base classes 
have been introduced for widgets, canvases and list walkers.  Some bugs 
have been fixed.  Python 2.2 or later is now required.

There were three major changes that contributed to the performance 
improvement in this release.  The Canvas class was rewritten so that 
canvases can be combined more efficiently.  Canvas objects are now 
cached so that most unchanged widgets will not need to re-render 
themselves.  There is a new C module for some of the heavily used 
low-level string functions contributed by Rebecca Breu.

Urwid's raw_display module may now be used with libraries like Twisted 
that have their own event loops.  Use the new get_input_descriptors() 
and get_input_nonblocking() methods instead of get_input() when using an 
external event loop.

While I have tried to maintain compatibility with older versions of 
Urwid, some of the changes in this release may affect existing code. 
Please report any problems you have to the mailing list or the IRC channel.

[1] http://article.gmane.org/gmane.comp.lib.urwid/415
[2] http://excess.org/urwid/browser/contrib/trunk


New in this release:


  * Rendering is now significantly faster.

  * New Widget base class for all widgets. It includes automatic caching
of rows() and render() methods. It also adds a new __super attribute
for accessing methods in superclasses.

Widgets must now call self._invalidate() to notify the cache when
their content has changed.

To disable caching in a widget set the class variable no_cache to a
list that includes the string render.

  * Canvas classes have been reorganized: Canvas has been renamed to
TextCanvas and Canvas is now the base class for all canvases. New
canvas classes include BlankCanvas, SolidCanvas and CompositeCanvas.

  * External event loops may now be used with the raw_display module. The
new methods get_input_descriptors() and get_input_nonblocking()
should be used instead of get_input() to allow input processing
without blocking.

  * The Columns, Pile and ListBox widgets now choose their first
selectable child widget as the focus widget by defaut.

  * New ListWalker base class for list walker classes.

  * New Signals class that will be used to improve the existing event
callbacks. Currently it is used for ListWalker objects to notify
their ListBox when their content has changed.

  * SimpleListWalker now behaves as a list and supports all list
operations. This class now detects when changes are made to the list
and notifies the ListBox object. New code should use this class to
wrap lists of widgets before passing them to the ListBox
constructor.

  * New PollingListWalker class is now the default list walker that is
used when passing a simple list to the ListBox constructor. This
class is intended for backwards compatibility only. When this class
is used the ListBox object is unable to cache its render() method.

  * The curses_display module can now draw in the lower-right corner of
the screen.

  * All display modules now have start() and stop() methods that may be
used instead of calling run_wrapper().

  * The raw_display module now uses an alternate buffer so that the
original screen can be restored on exit. The old behaviour is
available by seting the alternate_buffer parameter of start() or
run_wrapper() to False.

  * Many internal string processing functions have been rewritten in C to
improve their performance.

  * Compatible with Python = 2.2. Python 2.1 is no longer supported.


About Urwid
===

Urwid is a console UI library for Python. It features fluid interface
resizing, UTF-8 support, multiple text layouts, simple attribute markup,
powerful scrolling list boxes and flexible interface design.

Urwid is released under the GNU LGPL.




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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Unicode zipping from Python code?

2007-03-26 Thread durumdara
Hi!

As I experienced in the year 2006, the Python's zip module is not 
unicode-safe.
With the hungarian filenames I got wrong result.
I need to convert iso-8859-2 to cp852 chset to get good result.
As I see, this module is a command line tool imported as extension.

Now I search for something that can handle the characters good, or 
handle the unicode filenames.

Does anyone knows about a python project that can do this?
Or other tool what I can use for zipping intern. characters?

Thanks for your help!

dd

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


cgi python

2007-03-26 Thread Piyali Biswas
Hi Christian,

I have seen your well-solved cgi-python answers. That's why I think you
would be able to answer my query related to the same.

I am writing a cgi program and placing it in cgi-bin folder of Apache
Server. Now I have written a python script in the same folder to
generate a graph 'genebarchart.py'. 

 

When I run this program from shell, i.e.,

C:\Program Files\Apache Group\Apache2\cgi-binpython genebarchart.py

it runs well and creates the graph in htdocs folder as I save the graph
there using a save command within the python script, but when I use the
os.system command to call the python script within the cgi-code, i.e.,

os.system (python genebarchart.py)

as both the scripts are in the same folder, it doesn't creates the graph
in htdocs folder. Can u please tell me why?

 

Thanks,

Piyali

 

 

 

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

Re: any ways to judge whether an object is initilized or not in a class

2007-03-26 Thread Antoon Pardon
On 2007-03-20, Alex Martelli [EMAIL PROTECTED] wrote:
 Steven D'Aprano [EMAIL PROTECTED] wrote:
...
 There are plenty of reasons for preferring new style classes. If those
 reasons hold for you, then of course you should use new style classes.
 
 But that's not the same thing as saying that you should use new style
 classes *even when you don't care about those features*.

 You should always use new-style classes in order to avoid having to stop
 and make a decision each time you code a class -- having to stop and ask
 yourself do I need any of the many extra features of new-style classes
 here, or will legacy classes suffice? each and every time.

 There should ideally be only one obvious way -- and that obvious way is
 to always use new-style classes and avoid a feature that's there only
 for backwards compatibility with legacy code.

I disagree. The obvious way is to use old-style classes. IMO the obvious
way, is what a newbee will do after he has read the tutorial. And as far
as I am familiar with the tutorial someone trying out python after he
read it, will use old-style classes.

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


Re: Create new processes over telnet in XP

2007-03-26 Thread Laurent Pointal
Shane Geiger a écrit :
 This reminds me of something I once wanted to do:  How can I install
 Python in a totally non-gui way on Windows (without the use of VNC)?  I
 think I was telnetted into a computer (or something like that) and I was
 unable to run the usual Python installer because it uses a GUI.

Take a look at PortablePython, this may be the easy solution...

http://www.portablepython.com/


A+

Laurent.

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


Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Michael Bentley
On Mar 26, 2007, at 1:30 AM, Thomas Dybdahl Ahle wrote:
 Hi, I've writing a python application in which I'd like to have a  
 small
 ping label, to always tell the current ping time to the server.

 It seems however that I have to be root to send those imcp  
 packages, but
 I guess there must be a workaround since I can easily use the ping
 command as ordinary user.

 Do anybody know how to do this in python?


This won't solve your privileges issue, but this seems to get the  
ping time to server:

import socket
import os
import sys
import struct
import time
import select

# Derived from ping.c distributed in Linux's netkit. That code is
# copyright (c) 1989 by The Regents of the University of California.
# That code is in turn derived from code written by Mike Muuss of the
# US Army Ballistic Research Laboratory in December, 1983 and
# placed in the public domain. They have my thanks.

# Bugs are naturally mine. I'd be glad to hear about them. There are
# certainly word-size dependenceies here.

# Copyright (c) Matthew Dixon Cowles, http://www.visi.com/~mdc/.
# Distributable under the terms of the GNU General Public License
# version 2. Provided with no warranties of any sort.

# Note that ICMP messages can only be sent from processes running
# as root.

# Revision history:
#
# November 22, 1997
# Initial hack. Doesn't do much, but rather than try to guess
# what features I (or others) will want in the future, I've only
# put in what I need now.
#
# December 16, 1997
# For some reason, the checksum bytes are in the wrong order when
# this is run under Solaris 2.X for SPARC but it works right under
# Linux x86. Since I don't know just what's wrong, I'll swap the
# bytes always and then do an htons().
#
# December 4, 2000
# Changed the struct.pack() calls to pack the checksum and ID as
# unsigned. My thanks to Jerome Poincheval for the fix.
#

# From /usr/include/linux/icmp.h; your milage may vary.
ICMP_ECHO_REQUEST = 8 # Seems to be the same on Solaris.

# I'm not too confident that this is right but testing seems
# to suggest that it gives the same answers as in_cksum in ping.c
def checksum(str):
 csum = 0
 countTo = (len(str) / 2) * 2
 count = 0
 while count  countTo:
 thisVal = ord(str[count+1]) * 256 + ord(str[count])
 csum = csum + thisVal
 csum = csum  0xL # Necessary?
 count = count + 2

 if countTo  len(str):
 csum = csum + ord(str[len(str) - 1])
 csum = csum  0xL # Necessary?

 csum = (csum  16) + (csum  0x)
 csum = csum + (csum  16)
 answer = ~csum
 answer = answer  0x

 # Swap bytes. Bugger me if I know why.
 answer = answer  8 | (answer  8  0xff00)

 return answer

def receiveOnePing(mySocket, ID, timeout):
 timeLeft = timeout

 while 1:
 startedSelect = time.time()
 whatReady = select.select([mySocket], [], [], timeLeft)
 howLongInSelect = (time.time() - startedSelect)

 if whatReady[0] == []: # Timeout
 return -1

 timeReceived = time.time()
 recPacket, addr = mySocket.recvfrom(1024)
 icmpHeader = recPacket[20:28]
 typ, code, checksum, packetID, sequence = struct.unpack 
(bbHHh,
icmpHeader)

 if packetID == ID:
 bytesInDouble = struct.calcsize(d)
 timeSent = struct.unpack(d, recPacket[28:28 +
bytesInDouble])[0]
 return timeReceived - timeSent

 timeLeft = timeLeft - howLongInSelect

 if timeLeft = 0:
 return -1

def sendOnePing(mySocket, destAddr, ID):
 # Header is type (8), code (8), checksum (16), id (16), sequence  
(16)
 myChecksum = 0

 # Make a dummy heder with a 0 checksum.
 header = struct.pack(bbHHh, ICMP_ECHO_REQUEST, 0, myChecksum,  
ID, 1)
 bytesInDouble = struct.calcsize(d)
 data = (192 - bytesInDouble) * Q
 data = struct.pack(d, time.time()) + data

 # Calculate the checksum on the data and the dummy header.
 myChecksum = checksum(header + data)

 # Now that we have the right checksum, we put that in. It's just  
easier
 # to make up a new header than to stuff it into the dummy.
 if sys.platform == 'darwin':
 myChecksum = socket.htons(myChecksum)  0x
 else:
 myChecksum = socket.htons(myChecksum)

 header = struct.pack(bbHHh, ICMP_ECHO_REQUEST, 0,
 myChecksum, ID, 1)

 packet = header + data
 mySocket.sendto(packet, (destAddr, 1)) # Don't know about the 1

def doOne(destAddr, timeout=10):
 # Returns either the delay (in seconds) or none on timeout.
 icmp = socket.getprotobyname(icmp)
 mySocket = socket.socket(socket.AF_INET,socket.SOCK_RAW,icmp)
 myID = os.getpid()  0x
 sendOnePing(mySocket, destAddr, myID)
 delay = receiveOnePing(mySocket, myID, timeout)
 mySocket.close()

 return delay


def ping(host, timeout=1):
 dest = socket.gethostbyname(host)
 delay 

Re: Create new processes over telnet in XP

2007-03-26 Thread Tim Golden
Laurent Pointal wrote:
 Shane Geiger a écrit :
 This reminds me of something I once wanted to do:  How can I install
 Python in a totally non-gui way on Windows (without the use of VNC)?  I
 think I was telnetted into a computer (or something like that) and I was
 unable to run the usual Python installer because it uses a GUI.

While I don't remember if I've actually tried it you should
be able to do this with WMI. Example here...

   http://timgolden.me.uk/python/wmi_cookbook.html#install-a-product

If I have time to do it (and then undo whatever damage it
does ;) I'll give it a go later.

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


Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Michael Bentley

On Mar 26, 2007, at 1:30 AM, Thomas Dybdahl Ahle wrote:


 It seems however that I have to be root to send those imcp  
 packages, but
 I guess there must be a workaround since I can easily use the ping
 command as ordinary user.


The workaround your ping command is using btw, is probably running  
suid root.

hth,
Michael

---
Simplicity is the ultimate sophistication.
   -Leonardo da Vinci



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


Calling Queue experts

2007-03-26 Thread jrpfinch
I have a script which is based on the following code.  Unfortunately,
it only works on Python 2.3 and not 2.5 because there is no esema or
fsema attribute in the 2.5 Queue.  I am hunting through the Queue.py
code now to try to figure out how to make it work in 2.5, but as I am
a beginner, I am having difficulty and would appreciate your help.

Many thanks

Jon

import os
import Queue
import threading
import time
import cPickle

class PickleQueue(Queue.Queue):
A multi-producer, multi-consumer, persistent queue.


def __init__(self, filename, maxsize=0):
Initialize a persistent queue with a filename and maximum
size.


The filename is used as a persistent data store for the
queue.
If maxsize = 0, the queue size is infinite.

self.filename = filename
Queue.Queue.__init__(self, maxsize)
if self.queue:
self.esema.release()
if self._full():
self.fsema.acquire()


def _init(self, maxsize):
# Implements Queue protocol _init for persistent queue.
# Sets up the pickle files.
self.maxsize = maxsize
try:
self.readfile = file(self.filename, 'r')
self.queue = cPickle.load(self.readfile)
self.readfile.close()
except IOError, err:
if err.errno == 2:
# File doesn't exist, continue ...
self.queue = []
else:
# Some other I/O problem, reraise error
raise err
except EOFError:
# File was null?  Continue ...
self.queue = []


# Rewrite file, so it's created if it doesn't exist,
# and raises an exception now if we aren't allowed
self.writefile = file(self.filename, 'w')
cPickle.dump(self.queue, self.writefile, 1)


def __sync(self):
# Writes the queue to the pickle file.
self.writefile.seek(0)
cPickle.dump(self.queue, self.writefile, 1)
self.writefile.flush()


def _put(self, item):
# Implements Queue protocol _put for persistent queue.
self.queue.append(item)
self.__sync()


def _get(self):
# Implements Queue protocol _get for persistent queue.
item = self.queue[0]
del self.queue[0]
self.__sync()
return item

class counterThread(threading.Thread):
numberQueue = PickleQueue('/export/home/jrpf/data.pkl')
exitCounterQueue = Queue.Queue(1)

def run(self):
command = ''
i = 0
while 1:
self.numberQueue.put(i)
if i  10:
print i  10 so attempting to exit
wt.exit()
self.exit()


print i
try:
command = self.exitCounterQueue.get(block=False)
except Queue.Empty:
pass
if command == 'exit':
print Counter thread exited
break
i = i + 1
time.sleep(1)

def exit(self):
self.exitCounterQueue.put('exit')

def main():

ct = counterThread()
ct.setDaemon(True)
ct.start()
ct.join()

if __name__ == __main__:
main()

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


Re: Pattern for foo tool - API - shell|GUI

2007-03-26 Thread Anastasios Hatzis
On Sunday 25 March 2007 16:44, Steven Bethard wrote:
 Anastasios Hatzis wrote:
  I'm working on a tool which is totally command-line based and consisting
  of multiple scripts. The user can execute a Python script in the shell,
  this script does some basic verification before delegating a call into my
  tool's package and depending on some arguments and options provided in
  the command-line, e.g.
  $python generate.py myproject --force --verbose
  the tool processes whatever necessary. There are multiple command
  handlers available in this package which are responsible for different
  tasks and depending of the script that has been executed one or more of
  these command handlers are fired to do their work ;)

 Side note: you might find argparse (http://argparse.python-hosting.com/)

 makes this a bit easier if you have positional arguments or sub-commands::

Steve, thank you, for the note. I didn't know argparse before. I have multiple 
scripts since optparse puts all arguments and options into one single help 
text, and the arguments and options are too specific for most commands (and 
thus the help would be absolutely overloaded and useless for new users). It 
seems that argparse has multiple help pages separated for each sub-command, 
as far as I understand the page.


  And I don't think that this is very trivial (at least not for my
  programming skill level). In the given example generate.py (above) the
  following scenario is pretty likely:
 
  (1) User works with UML tool and clicks in some dialog a generate
  button (2) UML tool triggers this event an calls a magic generate()
  method of my tool (via the API I provide for this purpose), like my
  generate.py script would do same way
  (3) Somewhen with-in this generate process my tool may need to get some
  information from the user in order to continue (it is in the nature of
  the features that I can't avoid this need of interaction in any case).

 So you're imagining an API something like::

  def generate(name,
   force=False,
   verbose=False,
   handler=command_line_handler):
  ...
  choice = handler.prompt_user(question_text, user_choices)
  ...

 where the command-line handler might look something like::

  class CommandLineHandler(object):
  ...
  def prompt_user(self, question_text, user_choices):
  while True:
  choice = raw_input(question_text)
  if choice in user_choices:
  return choice
  print 'invalid choice, choose from %s' % choices

 and the GUI client would implement the equivalent thing with dialogs?

Exactly.

- Now, as I see your example, I wonder if this would work with a GUI which is 
event-driven... I have to look into my wx GUI prototype.

 That seems basically reasonable to me, though you should be clear in the
 documentation of generate() -- and any other methods that accept handler
 objects -- exactly what methods the handler must provide.

 You also may find that prompt_user is a bit too generic -- e.g. a file
 chooser dialog looks a lot different from a color chooser dialog -- so
 you may need to split this up into prompt_user_file,
 prompt_user_color, etc. so that handler's don't have to introspect the
 question text to know what to do...

 STeVe

Hey, right, good idea. I didn't think about the different task-specific 
dialogs in most GUIs. But I see that usability will gain benefit from 
differentiated prompt methods.

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


Re: Create new processes over telnet in XP

2007-03-26 Thread Tim Golden
Tim Golden wrote:
 Laurent Pointal wrote:
 Shane Geiger a écrit :
 This reminds me of something I once wanted to do:  How can I install
 Python in a totally non-gui way on Windows (without the use of VNC)?  I
 think I was telnetted into a computer (or something like that) and I was
 unable to run the usual Python installer because it uses a GUI.
 
 While I don't remember if I've actually tried it you should
 be able to do this with WMI. Example here...
 
http://timgolden.me.uk/python/wmi_cookbook.html#install-a-product
 
 If I have time to do it (and then undo whatever damage it
 does ;) I'll give it a go later.
 
 TJG

Or, indeed, just run it in quiet mode, according to the docs:

   http://www.python.org/download/releases/2.5/msi/

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


Re: problem at installing phyton on windows

2007-03-26 Thread bryan rasmussen

 Obviously, Phyton will never be defined.


Indeed I remember in the climactic showdown between Phyton and the
rest of the gamma ranger FooDroids and he kept doing the mega kick
move. and I was thinking wow Phyton will never be defined, he will
just keep kicking ass.

I hear they're gonna make a Phyton Commandant movie.

Cheers,
Bryan Rasmussen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A better webpage filter

2007-03-26 Thread Anton Vredegoor
John J. Lee wrote:

 http://webcleaner.sourceforge.net/

Thanks, I will look into it sometime. Essentially my problem has been 
solved by switching to opera, but old habits die hard and I find myself 
using Mozilla and my little script more often than would be logical.

Maybe the idea of having a *Python* script open at all times to which 
all content goes through is just too tempting. I mean if there's some 
possible irritation on a site theoretically I could just write a 
specific function to get rid of it. This mental setting works as a 
placebo on my web browsing experience so that the actual problems don't 
always even need  to be solved ... I hope I'm not losing all traditional 
programmers here in this approach :-)

 Not actually tried it myself, though did browse some of the code once
 or twice -- does some clever stuff.
 
 Lots of other Python-implemented HTTP proxies, some of which are
 relevant (though AFAIK all less sophisticated than webcleaner), are
 listed on Alan Kennedy's nice page here:
 
 http://xhaus.com/alan/python/proxies.html
 
 
 A surprising amount of diversity there.

At least now I know what general category seems to be nearest to my 
solution so thanks again for that. However my solution is not really 
doing anything like the programs on this page (although it is related to 
removing ads), instead it tries to modulate a copy of the page after 
it's been saved on disk. This removes all kinds of links and enables one 
to definitely and finally reshape the form the page will take. As such 
it is more concerned with the metaphysical image the page makes on the 
users brain and less with the actual content or the security aspects.

One thing I noticed though on that (nice!) Alan Kennedy page is that 
there was a script that was so small that it didn't even have a homepage 
but instead it just relied on a google groups post! I guess you can see 
that I liked that one :-)

My filter is even smaller. I've tried to make it smaller still by 
removing the batch file and using webbrowser.open(some cStringIO object) 
but that didn't work on windows.

regards,

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


Grid and scrollbars

2007-03-26 Thread BH
Hi,

I am trying to build my own IHM with two treeCtrl and 1 grid, based on 
the wx.aui demos.
My problem is with the Grid. It dosen't have scrollbars.
I tried many methods (fit) but it always fail.

Can somebody point me where is the mistake ?

Thx

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wx
import wx.aui
import wx.grid
import wx.html
import sys,os
import images

# stuff for debugging
print wx.version:, wx.version()
print pid:, os.getpid()
##raw_input(Press Enter...)

assertMode = wx.PYAPP_ASSERT_DIALOG
##assertMode = wx.PYAPP_ASSERT_EXCEPTION

text = \
Hello World! TXT


overview = \
htmlbody
h3Hello World ! HTML/h3

/body/html



class MyFrame(wx.Frame):
 def __init__(self, parent, id=-1, title='wx.aui Test',
  size=(1024, 768), style=wx.DEFAULT_FRAME_STYLE):
 wx.Frame.__init__(self, parent, id, title, (0,0), size, style)

 self._mgr = wx.aui.AuiManager(self)

 self.data = [[1010, The foo doesn't bar, major, 1, 'MSW', 
1, 1, 1, 1.12],
 [1011, I've got a wicket in my wocket, wish list, 2, 
'other', 0, 0, 0, 1.50],
 [1012, Rectangle() returns a triangle, critical, 5, 
'all', 0, 0, 0, 1.56]
 ]


 self.grid = CustTableGrid(self, self.data)

 mb = wx.MenuBar()

 file_menu = wx.Menu()
 file_menu.Append(wx.ID_EXIT, Exit)
 mb.Append(file_menu, File)
 self.SetMenuBar(mb)

 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
 self.statusbar.SetStatusWidths([-2, -3])
 self.statusbar.SetStatusText(Ready, 0)
 self.statusbar.SetStatusText(Welcome To wxPython!, 1)


 tb2 = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
  wx.TB_FLAT | wx.TB_NODIVIDER)
 tb2.SetToolBitmapSize(wx.Size(16,16))
 tb2_bmp1 = wx.ArtProvider_GetBitmap(wx.ART_QUESTION, 
wx.ART_OTHER, wx.Size(16, 16))
 tb2.AddLabelTool(101, Test, tb2_bmp1)
 tb2.AddLabelTool(101, Test, tb2_bmp1)
 tb2.AddLabelTool(101, Test, tb2_bmp1)
 tb2.AddLabelTool(101, Test, tb2_bmp1)
 tb2.AddSeparator()
 tb2.AddLabelTool(101, Test, tb2_bmp1)
 tb2.AddLabelTool(101, Test, tb2_bmp1)
 tb2.Realize()

 #Toolbar
 self._mgr.AddPane(tb2, wx.aui.AuiPaneInfo().
   Name(tb2).Caption(Toolbar 2).
   ToolbarPane().Top().Row(1).
   LeftDockable(False).RightDockable(False))
 #Grid
 self._mgr.AddPane(self.grid, wx.aui.AuiPaneInfo().
   Name(Matrice).Caption(Matrice).
 
Center().Layer(1).Position(1).CloseButton(True).MaximizeButton(True))
 #Tree Left
 self._mgr.AddPane(self.CreateTreeCtrl(), wx.aui.AuiPaneInfo().
   Name(Q).Caption(Tree Pane).
 
Left().Layer(1).Position(1).CloseButton(True).MaximizeButton(True))
 #Tree Right
 self._mgr.AddPane(self.CreateTreeCtrl(), wx.aui.AuiPaneInfo().
   Name(Quest).Caption(Tree Pane).
 
Right().Layer(1).Position(1).CloseButton(True).MaximizeButton(True))



 self._mgr.Update()

 self.Bind(wx.EVT_CLOSE, self.OnClose)
 self.Bind(wx.EVT_MENU, self.OnClose, id=wx.ID_EXIT)

 def CreateTreeCtrl(self):

 tree = wx.TreeCtrl(self, -1, wx.Point(0, 0), wx.Size(160, 250),
wx.TR_DEFAULT_STYLE | wx.NO_BORDER)


 root = tree.AddRoot(Root)
 items = []

 imglist = wx.ImageList(16, 16, True, 2)
 imglist.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, 
wx.ART_OTHER, wx.Size(16,16)))
 imglist.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, 
wx.ART_OTHER, wx.Size(16,16)))
 tree.AssignImageList(imglist)


 tree.AppendItem(root, Root, 1)
 items.append(tree.AppendItem(root, Item 1, 0))
 items.append(tree.AppendItem(root, Item 2, 0))
 items.append(tree.AppendItem(root, Item 3, 0))
 items.append(tree.AppendItem(root, Item 4, 0))
 items.append(tree.AppendItem(root, Item 5, 0))

 for ii in xrange(len(items)):

 id = items[ii]
 tree.AppendItem(id, Subitem 1, 1)
 tree.AppendItem(id, Subitem 2, 1)
 tree.AppendItem(id, Subitem 3, 1)
 tree.AppendItem(id, Subitem 4, 1)
 tree.AppendItem(id, Subitem 5, 1)

 tree.Expand(root)

 return tree

 def CreateHTMLCtrl(self):
 ctrl = wx.html.HtmlWindow(self, -1, wx.DefaultPosition, 
wx.Size(400, 300))
 if gtk2 in wx.PlatformInfo:
 ctrl.SetStandardFonts()
 ctrl.SetPage(self.GetIntroText())
 return ctrl

 def GetIntroText(self):
 return overview

 def OnClose(self, event):
 # deinitialize the frame manager
 self._mgr.UnInit()
 # delete the frame
 self.Destroy()


class CustomDataTable(wx.grid.PyGridTableBase):
  

Re: detect suprocess interaction

2007-03-26 Thread Nick Craig-Wood
Robin Becker [EMAIL PROTECTED] wrote:
  I'm using subprocess to carry out svn commands (probably should use the svn 
 api 
  package, but that's a dependency too far). Anyhow my code looks like
 
  from subprocess import Popen, PIPE
  p = Popen((svn,'ls',u),stdout=PIPE,stderr=PIPE)
  i = p.wait()
 
  and this sort of thing works well under most circumstances. However, when 
 this 
  code is executed for the very first time by a particular user it hangs 
 waiting 
  on user input.
 
  This code is being used purely for testing correctness of a particular svn 
 url 
  so in the normal case we want to throw away both stdout and stderr. In the 
  exceptional case is it possible to detect that input is required and only in 
  that case issue the current contents of stdout (presumably a request for a 
  password)?
 
  Clearly I need to supply some kind of input filelike object, but is this 
 sort of 
  thing possible.

Yes it is possible, but if you try it you'll find you'll need to
implement the fileno() method of file objects which is asked to return
an OS file handle.  This is obviously a problem!

In general subprocess isn't really designed for interactive
processes like the above.  You'll find it much easier to use pexpect
for interactive stuff.

Note that svn has its own devious ways of finding a terminal to ask
the user for the password, eg...

$ svn ls svn+ssh://[EMAIL PROTECTED]/svn /dev/null /dev/null 21
Password: 

I don't know exactly how it does that but I suspect it is to do with
the controlling terminal...

On my system

$ setsid svn ls svn+ssh://[EMAIL PROTECTED]/svn /dev/null /dev/null 21

Pops up a gui box asking for the password!

You can simulate the above with

  Popen(..., stdin=file(os.devnull,r), preexec_fn=os.setsid)

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python object overhead?

2007-03-26 Thread Bruno Desthuilliers
Matt Garman a écrit :
 I'm trying to use Python to work with large pipe ('|') delimited data
 files.

Looks like a job for the csv module (in the standard lib).

  The files range in size from 25 MB to 200 MB.
 
 Since each line corresponds to a record, what I'm trying to do is
 create an object from each record.  However, it seems that doing this
 causes the memory overhead to go up two or three times.
 
 See the two examples below: running each on the same input file
 results in 3x the memory usage for Example 2.  (Memory usage is
 checked using top.)

Just for the record, *everything* in Python is an object - so the 
problem is not about 'using objects'. Now Of course, a complex object 
might eat up more space than a simple one...

Python has 2 simple types for structured data : tuples (like database 
rows), and dicts (associative arrays). You can use the csv module to 
parse a csv-like format into either tuples or dicts. If you want to save 
memory, tuples may be the best choice.

 This happens for both Python 2.4.3 on Gentoo Linux (64bit) and Python
 2.3.4 on CentOS 4.4 (64bit).
 
 Is this just the way it is or am I overlooking something obvious?

What are you doing with your records ? Do you *really* need to keep the 
whole list in memory ? Else you can just work line by line:

source = open(sys.argv[1])
for line in source:
   do_something_with(line)
source.close()

This will avoid building a huge in-memory list.

While we're at it, your snippets are definitively unpythonic and 
overcomplicated:


(snip)
 filedata = list()
 file = open(sys.argv[1])
 while True:
line = file.readline()
if len(line) == 0: break # EOF
filedata.append(line)
 file.close()
(snip)

filedata = open(sys.argv[1]).readlines())


 Example 2: read lines into objects:
 # begin readobjects.py
 import sys, time
 class FileRecord:

class FileRecord(object):

def __init__(self, line):
self.line = line

If this is your real code, I don't see any reason why this should eat up 
3 times more space than the original version.

 records = list()
 file = open(sys.argv[1])
 while True:
line = file.readline()
if len(line) == 0: break # EOF
rec = FileRecord(line)
records.append(rec)
 file.close()

records = map(FileRecord, open(sys.argv[1]).readlines()))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python object overhead?

2007-03-26 Thread Bruno Desthuilliers
Felipe Almeida Lessa a écrit :
 On 3/23/07, Bjoern Schliessmann
 [EMAIL PROTECTED] wrote:
 (Note that almost everything in Python is an object!)
 
 Could you tell me what in Python isn't an object? 

statements and expressions ?-)

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

Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Michal 'vorner' Vaner
On Mon, Mar 26, 2007 at 08:30:16AM +0200, Thomas Dybdahl Ahle wrote:
 Hi, I've writing a python application in which I'd like to have a small 
 ping label, to always tell the current ping time to the server.
 
 It seems however that I have to be root to send those imcp packages, but 
 I guess there must be a workaround since I can easily use the ping 
 command as ordinary user.
 
 Do anybody know how to do this in python?

You need root for that and the ping command is allowed to have them by
suid bit. You can execute ping from inside python and use ping as is, if
you need.

-- 
This is a terroristic email. It will explode in 10 minutes, 
if you do not close it in the meantime.

Michal vorner Vaner


pgpGCsSHtsxLl.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: creating jsp-like tool with python

2007-03-26 Thread Bruno Desthuilliers
jd a écrit :
 I'd like to create a program that takes files with jsp-like markup
 and processes the embedded code (which would be python) to produce the
 output file.  There would be two kinds of sections in the markup file:
 python code to be evaluated, and python code that returns a value that
 would be inserted into the output.
 
 This seems like it would be straightforward in python, and maybe
 there's even a library that I could use for this, but as a newbie to
 Python, I don't know the landscape very well.  I am not looking for a
 big framework, just something small and simple that will do just this
 job.  Suggestions or pointers would be greatly appreciated.

There are already quite a few Python templating solutions. You may want 
to look for:
- Python server pages
- Mighty
- Mako
- Jinja
- Genshi
- Cheetah
- Newov
- Zope Page Templates
- SimpleTAL (standalone implementation of ZPT)
- (add your favorite Python templating system here)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python object overhead?

2007-03-26 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit :
 Matt Garman a écrit :
(snip)
 class FileRecord(object):
 
def __init__(self, line):
self.line = line
 
 If this is your real code, I don't see any reason why this should eat up 
 3 times more space than the original version.
 

Hem... Forget about this comment - not enough coffein yet I'm afraid.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Queue experts

2007-03-26 Thread jrpfinch
Got it.  New PickleQueue class should be as follows:

import Queue
import cPickle

class PickleQueue(Queue.Queue):
A multi-producer, multi-consumer, persistent queue.


def __init__(self, filename, maxsize=0):
Initialize a persistent queue with a filename and maximum
size.


The filename is used as a persistent data store for the
queue.
If maxsize = 0, the queue size is infinite.

self.filename = filename
Queue.Queue.__init__(self, maxsize)
print self.queue

def _init(self, maxsize):
# Implements Queue protocol _init for persistent queue.
# Sets up the pickle files.
self.maxsize = maxsize
try:
self.readfile = file(self.filename, 'r')
self.queue = cPickle.load(self.readfile)
self.readfile.close()
except IOError, err:
if err.errno == 2:
# File doesn't exist, continue ...
self.queue = Queue.deque()
else:
# Some other I/O problem, reraise error
raise err
except EOFError:
# File was null?  Continue ...
self.queue = Queue.deque()


# Rewrite file, so it's created if it doesn't exist,
# and raises an exception now if we aren't allowed
self.writefile = file(self.filename, 'w')
cPickle.dump(self.queue, self.writefile, 1)


def __sync(self):
# Writes the queue to the pickle file.
self.writefile.seek(0)
cPickle.dump(self.queue, self.writefile, 1)
self.writefile.flush()


def _put(self, item):
# Implements Queue protocol _put for persistent queue.
self.queue.append(item)
self.__sync()


def _get(self):
# Implements Queue protocol _get for persistent queue.
item = self.queue.popleft()
self.__sync()
return item

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


with timeout(...):

2007-03-26 Thread Nick Craig-Wood
Did anyone write a contextmanager implementing a timeout for
python2.5?

I'd love to be able to write something like

with timeout(5.0) as exceeded:
some_long_running_stuff()
if exceeded:
print Oops - took too long!

And have it work reliably and in a cross platform way!

From my experiments with timeouts I suspect it won't be possible to
implement it perfectly in python 2.5 - maybe we could add some extra
core infrastructure to Python 3k to make it possible?

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: with timeout(...):

2007-03-26 Thread James Stroud
Nick Craig-Wood wrote:
 Did anyone write a contextmanager implementing a timeout for
 python2.5?
 
 I'd love to be able to write something like
 
 with timeout(5.0) as exceeded:
 some_long_running_stuff()
 if exceeded:
 print Oops - took too long!
 
 And have it work reliably and in a cross platform way!
 
 From my experiments with timeouts I suspect it won't be possible to
 implement it perfectly in python 2.5 - maybe we could add some extra
 core infrastructure to Python 3k to make it possible?
 

I'm guessing your question is far over my head, but if I understand it, 
I'll take a stab:

First, did you want the timeout to kill the long running stuff?

I'm not sure if its exactly what you are looking for, but I wrote a 
timer class that does something like you describe:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/464959

Probably you can do whatever you want upon timeout by passing the 
appropriate function as the expire argument.

This works like a screen saver, etc.

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


Re: Need help to learn Python

2007-03-26 Thread Eddie Corns
wesley chun [EMAIL PROTECTED] writes:

with that said, i would still like to state that the book's target
audience is for people who know how to program but need to pick up
Python as quickly as possible.  the theory that's in the book is
really more explanation of how the Python interpreter works,
especially the relationship between objects and memory management.
the goal is to give you enough of an understanding of how Python works
under the covers that you will write very effective code, even as a
beginner to the language.

Worked for me.  The 1/e was the easiest intro to a language I've ever read.
(I don't suppose you fancy doing one for Ruby :)

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


Re: functions, classes, bound, unbound?

2007-03-26 Thread Bruno Desthuilliers
7stud a écrit :
 ...classes don't invoke the function directly, they convert it to
 an 'unbound method' object::
(snip)
 
 If you really want to get to the original function, there are a couple
 of options.  
 
 No.  Just trying to figure out how some things work.

Most of Python's object model is documented here:

http://www.python.org/download/releases/2.2.3/descrintro/
http://users.rcn.com/python/download/Descriptor.htm


HTH

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


Re: Other classes in a module

2007-03-26 Thread Bruno Desthuilliers
Daniel Nogradi a écrit :
 Can an instance of a class in a module, in any simple way find out which
 other classes that exists in said module ?
 
 
 # module x ##
 class c1:
pass
 
 class c2:
pass
 ###
 
 
 Python 2.5 (r25:51908, Nov  1 2006, 11:42:37)
 [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
 Type help, copyright, credits or license for more information.
 import types
 import x
 for i in dir(x):
 ... if type(getattr(x,i)) is types.ClassType:
 ... print Hey, '%s' is a class! % i
 ...
 Hey, 'c1' is a class!
 Hey, 'c2' is a class!

 
 
 It might be not exactly what you want but maybe still helps.

Doesn't work with new-style classes:

  class Foo(object): pass
...
  import typs
Traceback (most recent call last):
   File stdin, line 1, in ?
ImportError: No module named typs
  import types
  type(Foo) is types.ClassType
False
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Nick Craig-Wood
Michael Bentley [EMAIL PROTECTED] wrote:
  On Mar 26, 2007, at 1:30 AM, Thomas Dybdahl Ahle wrote:
  It seems however that I have to be root to send those imcp
  packages, but I guess there must be a workaround since I can
  easily use the ping command as ordinary user.
 
  The workaround your ping command is using btw, is probably running  
  suid root.

Under linux the only priviledge you need is CAP_NET_RAW.  It is
possible to give this to a process - a bit of searching with google
will show you how!

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the second of nested buttons using textvariable remains void!

2007-03-26 Thread Samkos
Thanks a lot Jim and James

now it works fine!

Sam

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


Re: python on window

2007-03-26 Thread sandeep patil
i have written this program but i have gott following error,
in anather proram indentation error sir how i will indent in my
editor

#test.py
 def invert(table):
index=()
for key in table:
value=table[key]
if not index.has_key(value):
index[value]=[]
index[value].append(key)
return index


 phonebook = {'sandeep':9325, 'amit':9822, 'anand':9890, 'titu': 9325}
 phonebook
{'titu': 9325, 'amit': 9822, 'anand': 9890, 'sandeep': 9325}
 print phonebook
{'titu': 9325, 'amit': 9822, 'anand': 9890, 'sandeep': 9325}
 inverted_phonebook = invert(phonebook)

Traceback (most recent call last):
  File pyshell#13, line 1, in module
inverted_phonebook = invert(phonebook)
  File pyshell#9, line 5, in invert
if not index.has_key(value):
AttributeError: 'tuple' object has no attribute 'has_key'
 interted_phonebook= invert(phonebook)

Traceback (most recent call last):
  File pyshell#14, line 1, in module
interted_phonebook= invert(phonebook)
  File pyshell#9, line 5, in invert
if not index.has_key(value):
AttributeError: 'tuple' object has no attribute 'has_key'


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


Re: with timeout(...):

2007-03-26 Thread Diez B. Roggisch
Nick Craig-Wood wrote:

 Did anyone write a contextmanager implementing a timeout for
 python2.5?
 
 I'd love to be able to write something like
 
 with timeout(5.0) as exceeded:
 some_long_running_stuff()
 if exceeded:
 print Oops - took too long!
 
 And have it work reliably and in a cross platform way!

Cross platform isn't the issue here - reliability though is. To put it
simple: can't be done that way. You could of course add a timer to the
python bytecode core, that would jump back to a stored savepoint or
something like that.

But to make that work reliably, it has to be ensured that no sideeffects
occur while being in some_long_running_stuff. which doesn't only extend to
python itself, but also external modules and systems (file writing, network
communications...). Which can't be done, unless you use a time-machine.
Which I'd take as an personal insult, because in that rolled-back timeframe
I will be possibly proposing to my future wife or something...

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


Re: python on window

2007-03-26 Thread Parthan SR

On 26 Mar 2007 05:00:54 -0700, sandeep patil [EMAIL PROTECTED] wrote:


i have written this program but i have gott following error,
in anather proram indentation error sir how i will indent in my
editor

#test.py
 def invert(table):
index=()
for key in table:
value=table[key]
if not index.has_key(value):
index[value]=[]
index[value].append(key)
return index


 phonebook = {'sandeep':9325, 'amit':9822, 'anand':9890, 'titu': 9325}
 phonebook
{'titu': 9325, 'amit': 9822, 'anand': 9890, 'sandeep': 9325}
 print phonebook
{'titu': 9325, 'amit': 9822, 'anand': 9890, 'sandeep': 9325}
 inverted_phonebook = invert(phonebook)

Traceback (most recent call last):
  File pyshell#13, line 1, in module
inverted_phonebook = invert(phonebook)
  File pyshell#9, line 5, in invert
if not index.has_key(value):
AttributeError: 'tuple' object has no attribute 'has_key'
 interted_phonebook= invert(phonebook)

Traceback (most recent call last):
  File pyshell#14, line 1, in module
interted_phonebook= invert(phonebook)
  File pyshell#9, line 5, in invert
if not index.has_key(value):
AttributeError: 'tuple' object has no attribute 'has_key'





In your code, index = () means it is a tuple. IIRC, it should be a
dictionary. For that, index = {}. This is the one causing the following
error in your code,

 if not index.has_key(value):
AttributeError: 'tuple' object has no attribute 'has_key'

You can not use has_key over a tuple object.

But where is the indentation error ? I see nothing like that in the error
message.


--
With Regards

---
Parthan.S.R.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Calling Queue experts

2007-03-26 Thread skip

jrpfinch # Some other I/O problem, reraise error
jrpfinch raise err

I'd just execute a bare raise (without err).  That way the caller gets the
stack trace of the actual IOError.

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


Re: A better webpage filter

2007-03-26 Thread Gabriel Genellina
En Mon, 26 Mar 2007 06:06:00 -0300, Anton Vredegoor  
[EMAIL PROTECTED] escribió:

 Thanks, I will look into it sometime. Essentially my problem has been
 solved by switching to opera, but old habits die hard and I find myself
 using Mozilla and my little script more often than would be logical.

 Maybe the idea of having a *Python* script open at all times to which
 all content goes through is just too tempting. I mean if there's some
 possible irritation on a site theoretically I could just write a
 specific function to get rid of it. This mental setting works as a

If you don't mind using JavaScript instead of Python, UserJS is for you:  
http://www.opera.com/support/tutorials/userjs/

-- 
Gabriel Genellina

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


Re: with timeout(...):

2007-03-26 Thread irstas
On Mar 26, 3:16 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 But to make that work reliably, it has to be ensured that no sideeffects
 occur while being in some_long_running_stuff. which doesn't only extend to
 python itself, but also external modules and systems (file writing, network
 communications...). Which can't be done, unless you use a time-machine.

Hey hey, isn't the Python mantra that we're all adults here? It'd
be the programmers responsibility to use only code that has no
side effects. I certainly can ensure that no side-effects occur in the
following code: 1+2. I didn't even need a time machine to do that :P
Or the primitive could be implemented so that Python
throws a TimeoutException at the earliest opportunity. Then one
could write except-blocks which deal with rolling back any undesirable
side effects. (I'm not saying such timeout feature could be
implemented in
Python, but it could be made by modifying the CPython implementation)

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


Re: Calling Queue experts

2007-03-26 Thread Gabriel Genellina
En Mon, 26 Mar 2007 07:29:32 -0300, jrpfinch [EMAIL PROTECTED] escribió:

 Got it.  New PickleQueue class should be as follows:

Only a comment:

 def _init(self, maxsize):
 # Implements Queue protocol _init for persistent queue.
 # Sets up the pickle files.
 self.maxsize = maxsize
 try:
 self.readfile = file(self.filename, 'r')
 self.queue = cPickle.load(self.readfile)
 self.readfile.close()
 except IOError, err:
 if err.errno == 2:
 # File doesn't exist, continue ...
 self.queue = Queue.deque()
 else:
 # Some other I/O problem, reraise error
 raise err
 except EOFError:
 # File was null?  Continue ...
 self.queue = Queue.deque()


 # Rewrite file, so it's created if it doesn't exist,
 # and raises an exception now if we aren't allowed
 self.writefile = file(self.filename, 'w')
 cPickle.dump(self.queue, self.writefile, 1)

self.readfile may be left open in case of error, I'd use a try/finally.  
And since it isn't used anywhere, I'd just use a local variable instead of  
an instance attribute.
And the final write is not necesary when you have just read it - and  
alters the last-modified-time (that may not be relevant for you, of  
course, but as a general tool it may confuse other users).

-- 
Gabriel Genellina

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


Re: python on window

2007-03-26 Thread Michael Bentley

On Mar 26, 2007, at 7:00 AM, sandeep patil wrote:
 i have written this program but i have gott following error,
 in anather proram indentation error sir how i will indent in my
 editor

 #test.py
 def invert(table):
   index=()
   for key in table:
   value=table[key]
   if not index.has_key(value):
   index[value]=[]
   index[value].append(key)
   return index


 phonebook = {'sandeep':9325, 'amit':9822, 'anand':9890, 'titu':  
 9325}
 phonebook
 {'titu': 9325, 'amit': 9822, 'anand': 9890, 'sandeep': 9325}
 print phonebook
 {'titu': 9325, 'amit': 9822, 'anand': 9890, 'sandeep': 9325}
 inverted_phonebook = invert(phonebook)

 Traceback (most recent call last):
   File pyshell#13, line 1, in module
 inverted_phonebook = invert(phonebook)
   File pyshell#9, line 5, in invert
 if not index.has_key(value):
 AttributeError: 'tuple' object has no attribute 'has_key'

If you define index as a dict instead of a tuple, you'll stop getting  
that error -- but I'm afraid it still won't do what you want.  Are  
you trying to get a phonebook in which the values of the original  
phonebook are the keys of the new one -- and the values are lists  
(both 'sandeep' and 'titu' have the same number)?  If so, try this:

def invert(table):
index=dict()
for k,v in table.items():
if index.has_key(v):
index[v].append(k)
else:
index[v] = [k]
return index

You had mentioned something about indentation error...  If you'll  
look at your definition of invert(), you can see that 'return index'  
is inside the for loop -- which would cause a return before the  
second time through the for loop.  By dedenting (is that a word?) so  
'return' falls directly below 'for', the for loop would have been  
able to run to completion before returning.

Hope this helps,
Michael

---

Our network was brought down by a biscuit??? --Steven D'Aprano



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


osx tkinter listbox problem

2007-03-26 Thread Ben Collver
I am using Darwin 10.4.9, tcl 8.4.7, tk 8.4, and python 2.3.5.  I have 
also tried Python 2.5 on Darwin, Debian, and Fedora Core 6.

I am working on a GUI front-end to a Python program of mine.  It is a 
simple grid with labels in the left column and input widgets in the 
right column.  One of the rows has a listbox in the right column.  The 
listbox contains two items.  I select one using widget.select_set(). 
The GUI is not complete yet, because I am still learning about Python 
and Tkinter.

On Linux, the GUI works as expected.  On OSX, when select_set() runs, 
the listbox disappears from its place in the grid, and appears in the 
upper left corner of the window.  Here are screen shots to illustrate.
http://terrorpin.net/~ben/docs/alt/music/soundfont/pysf-wip/pysfi-debian.jpg
http://terrorpin.net/~ben/docs/alt/music/soundfont/pysf-wip/pysfi-osx.png

The GUI code itself is at the following location.
http://terrorpin.net/~ben/docs/alt/music/soundfont/pysf-wip/pysfi.py

To run, it needs the Python program at the following location.
http://terrorpin.net/~ben/docs/alt/music/soundfont/pysf-wip/pysf.py

Why does the listbox change position at all?  Am I using listbox 
incorrectly?

Thank you,

Ben


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


Fortran vs Python - Newbie Question

2007-03-26 Thread [EMAIL PROTECTED]
OK...
I've been told that Both Fortran and Python are easy to read, and are
quite useful in creating scientific apps for the number crunching, but
then Python is a tad slower than Fortran because of its a high level
language nature, so what are the advantages of using Python for
creating number crunching apps over Fortran??
Thanks
Chris

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


Zip file writing progress (callback proc)

2007-03-26 Thread durumdara
Hi!

I want to check my zip file writings.
I need some callback procedure to show a progress bar.
Can I do that?
I don't want to modify the PyLib module to extend it, because if I get 
another py, the changes are lost.
This happening too if I copy the zip module to modify it.
Any solution?

Thanks for it:
dd
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Jean-Paul Calderone
On 26 Mar 2007 06:20:32 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
OK...
I've been told that Both Fortran and Python are easy to read, and are

Python is hugely easier to read.

quite useful in creating scientific apps for the number crunching, but
then Python is a tad slower than Fortran because of its a high level

Fortran is massively faster than Python.

language nature, so what are the advantages of using Python for
creating number crunching apps over Fortran??

You can get the speed of fortran in Python by using libraries like
Numeric without losing the readability of Python.

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread kyosohma
On Mar 26, 8:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 OK...
 I've been told that Both Fortran and Python are easy to read, and are
 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level
 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??
 Thanks
 Chris

While I have never personally dealt with Fortran, I looked it up here:

http://en.wikipedia.org/wiki/Fortran_code_examples

The code examples speak for themselves. I recommend you look those
over and then look over similar simple program written in Python.
Python is still easier to read. Fortran also appears to be a compiled
language, whereas Python is an interpreted language. Thus, Python
programs can be tested faster. Fortran programs will likely run faster
though.

Check out www.python.org for good examples of Python code for the
beginner and the advanced programmer.

Mike

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Michele Simionato
On Mar 26, 9:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 OK...
 I've been told that Both Fortran and Python are easy to read, and are
 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level
 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??
 Thanks
 Chris

The standard way is to perform the number crunching in Fortran and to
use
Python as glue. See for instance the scipy project, which includes the
f2py bridge.

 Michele Simionato

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Bart Ogryczak
On Mar 26, 3:20 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 OK...
 I've been told that Both Fortran and Python are easy to read, and are
 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level
 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??

Portability, scalability  RAD.



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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread [EMAIL PROTECTED]
On Mar 26, 2:42 pm, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On 26 Mar 2007 06:20:32 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 OK...
 I've been told that Both Fortran and Python are easy to read, and are

 Python is hugely easier to read.

 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level

 Fortran is massively faster than Python.

 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??





 You can get the speed of fortran in Python by using libraries like
 Numeric without losing the readability of Python.


Can you back this up with some source??
Chris

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


web development with python - comparison

2007-03-26 Thread Istvan Albert

Here is a comprehensive review of python web apps:

http://jesusphreak.infogami.com/blog/vrp1

Since this comes up every so often in this group.

i.

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Jean-Paul Calderone
On 26 Mar 2007 06:47:18 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
On Mar 26, 2:42 pm, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On 26 Mar 2007 06:20:32 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 OK...
 I've been told that Both Fortran and Python are easy to read, and are

 Python is hugely easier to read.

 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level

 Fortran is massively faster than Python.

 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??

 You can get the speed of fortran in Python by using libraries like
 Numeric without losing the readability of Python.


Can you back this up with some source??

Half the code in Numeric was compiled from fortran.  Need I go on? :)

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread stef


   
 You can get the speed of fortran in Python by using libraries like
 Numeric without losing the readability of Python.

 

 Can you back this up with some source??
 Chris

   
Is this really the most important issue in your choice ?

As said by others, Portability, scalability  RAD as an advantage of 
Python are probably far more important.

And on the other hand Python is perfect as glue between Fortran and 
whatsoever.
To emphasize that, I expect the number of lines in Python is at least 3 
times less than in Fortran.

I did some comparison between MatLab and Python  (Scipy) for real-time 
analysis,
and for all my cases Pyhton van 3 .. 7 times faster than MatLab.

So I'ld suggest to start with downloading the Enthought edition of Python,
and you can judge for yourself within 10 minutes,
if it's fast enough.

cheers,
Stef Mientki

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


Re: To count number of quadruplets with sum = 0

2007-03-26 Thread mark . dufour

 FWIW, the original program can also be compiled with Shed Skin (http://
 mark.dufour.googlepages.com), an experimental (static-)Python-to-C++
 compiler, resulting in a speedup of about 8 times for a single test
 with 500 tuples. here's a slightly modified version that works with
 Shed Skin CVS at least:

after optimizing dicts a bit for Shedskin 0.0.21 (http://
mark.dufour.googlepages.com), the speedup for this program is now
about 16.5 times for the same test.


Thanks,
Mark Dufour (Shed Skin author - send me bug reports!)


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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Andy Dingley
On 26 Mar, 14:20, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 what are the advantages of using Python for
 creating number crunching apps over Fortran??

If you have to ask, you've not experienced enough Fortran to know its
sheer horror.

You can write programs in Python that do usefully complicated things,
and you can get them to work in a reasonable time. Fortran can't do
this, for anything more than the trivial. Classic Fortran tasks of
the past are now seen as trivial. OK, so they did it to a lot of data,
but they really didn't do anything very complex to it.

You can also write Python that other people can read and maintain. You
can't do this in Fortran, without a truly insane amount of trouble. As
Fortran programs have historically been authored and hacked on by
successive generations of grad students, this is the most vital
feature of all.

Finally we're no longer so interested in number crunching. Number
crunching used to consist of simple operations over vast arrays of
data, although this was data with remarkably simple structure by
today's standards. These just aren't the major class of problems of
interest today. There's a massive difference between old-school FEA
(bashing Newton and Hooke into tinier and tinier cells) and
bioinformatics or anything involving the representation of big data
graphs.

 Python is a tad slower than Fortran

If the Fortran program turns out to have been broken all along, then
who cares?

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread [EMAIL PROTECTED]
On 26 Mar, 15:06, stef [EMAIL PROTECTED] wrote:
  You can get the speed of fortran in Python by using libraries like
  Numeric without losing the readability of Python.

  Can you back this up with some source??
  Chris

 Is this really the most important issue in your choice ?

 As said by others, Portability, scalability  RAD as an advantage of
 Python are probably far more important.

 And on the other hand Python is perfect as glue between Fortran and
 whatsoever.
 To emphasize that, I expect the number of lines in Python is at least 3
 times less than in Fortran.

 I did some comparison between MatLab and Python  (Scipy) for real-time
 analysis,
 and for all my cases Pyhton van 3 .. 7 times faster than MatLab.

 So I'ld suggest to start with downloading the Enthought edition of Python,
 and you can judge for yourself within 10 minutes,
 if it's fast enough.

 cheers,
 Stef Mientki

Is there a mac version??
Thanks
Chris

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread irstas
On Mar 26, 4:47 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  You can get the speed of fortran in Python by using libraries like
  Numeric without losing the readability of Python.

 Can you back this up with some source??
 Chris

If you execute one command in Python which tells a super-optimized
Fortran-routine to do lots of work, the overhead of Python will be
neglible. That's all there is to it, no need for a source.

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
   ...
  So I'ld suggest to start with downloading the Enthought edition of Python,
  and you can judge for yourself within 10 minutes,
  if it's fast enough.
 
  cheers,
  Stef Mientki
 
 Is there a mac version??

http://download.enthought.com/MacEnthon/ReadMe.html but it's self
labeled as 0.1 Test Release i.e. somewhat preliminary; it claims to
support only Panther (10.3) and its 2.3.0 Python (no claims for Tiger,
10.4, and its 2.3.5 Python, nor for other Python Mac istalls yet).

If you're just trying to learn and check things out, it might be better
to get a more recent Python from python.org (2.5 or 2.4.4) and the
various other packages as and when you need them (you can use the
MacEnthon list as a guide:-).  You'll need a C compiler to be sure you
can install any package from sources -- Apple's XCode includes gcc, it's
free, and it's the safest choice (but it's a HUGE download, as it comes
with a lot of stuff -- I don't think Apple offers a simple way to
install just gcc and minimal supporting tools).


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


Re: A better webpage filter

2007-03-26 Thread Anton Vredegoor
Gabriel Genellina wrote:

 If you don't mind using JavaScript instead of Python, UserJS is for you:  
 http://www.opera.com/support/tutorials/userjs/

My script loads a saved copy of a page and uses it to open an extra tab 
with a filtered view. It also works when javascript is disabled.

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


Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Thomas Dybdahl Ahle
Den Mon, 26 Mar 2007 11:24:34 +0200 skrev Michal 'vorner' Vaner:
 On Mon, Mar 26, 2007 at 08:30:16AM +0200, Thomas Dybdahl Ahle wrote:

 Do anybody know how to do this in python?

 You need root for that and the ping command is allowed to have them by
 suid bit. You can execute ping from inside python and use ping as is, if
 you need.

Yeah, I could execute ping, but it would lock me harder to the platform.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Thomas Dybdahl Ahle
Den Mon, 26 Mar 2007 06:30:04 -0500 skrev Nick Craig-Wood:

 Michael Bentley [EMAIL PROTECTED] wrote:
  On Mar 26, 2007, at 1:30 AM, Thomas Dybdahl Ahle wrote:
  It seems however that I have to be root to send those imcp packages,
  but I guess there must be a workaround since I can easily use the
  ping command as ordinary user.
 
  The workaround your ping command is using btw, is probably running
  suid root.
 
 Under linux the only priviledge you need is CAP_NET_RAW.  It is possible
 to give this to a process - a bit of searching with google will show you
 how!

How, I did google, but I wasn't able to find any way to do this in 
python..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zip file writing progress (callback proc)

2007-03-26 Thread irstas
On Mar 26, 4:41 pm, durumdara [EMAIL PROTECTED] wrote:
 Hi!

 I want to check my zip file writings.
 I need some callback procedure to show a progress bar.
 Can I do that?
 I don't want to modify the PyLib module to extend it, because if I get
 another py, the changes are lost.
 This happening too if I copy the zip module to modify it.
 Any solution?

 Thanks for it:
 dd

Would it be enough to show progress based on how many files have
been added to the zip? If you're zipping just one huge file, I'm
afraid you can't get a progress bar using the zipfile module.

If it's not necessary that the one file is a zip but simply
compressed,
you can use zlib or bz2 modules to compress incrementally:
http://www.python.org/doc/lib/node303.html


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


Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Jean-Paul Calderone
On Mon, 26 Mar 2007 16:50:33 +0200, Thomas Dybdahl Ahle [EMAIL PROTECTED] 
wrote:
Den Mon, 26 Mar 2007 06:30:04 -0500 skrev Nick Craig-Wood:

 Michael Bentley [EMAIL PROTECTED] wrote:
  On Mar 26, 2007, at 1:30 AM, Thomas Dybdahl Ahle wrote:
  It seems however that I have to be root to send those imcp packages,
  but I guess there must be a workaround since I can easily use the
  ping command as ordinary user.

  The workaround your ping command is using btw, is probably running
  suid root.

 Under linux the only priviledge you need is CAP_NET_RAW.  It is possible
 to give this to a process - a bit of searching with google will show you
 how!

How, I did google, but I wasn't able to find any way to do this in
python..

You need a sendmsg wrapper (there are several, none in the stdlib), then
you need a privileged process which is willing to give you the privilege.

It's pretty inconvenient.

Jean-Paul

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Cameron Laird
In article [EMAIL PROTECTED],
Jean-Paul Calderone  [EMAIL PROTECTED] wrote:
On 26 Mar 2007 06:20:32 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
OK...
I've been told that Both Fortran and Python are easy to read, and are

Python is hugely easier to read.

quite useful in creating scientific apps for the number crunching, but
then Python is a tad slower than Fortran because of its a high level

Fortran is massively faster than Python.

language nature, so what are the advantages of using Python for
creating number crunching apps over Fortran??

You can get the speed of fortran in Python by using libraries like
Numeric without losing the readability of Python.

Jean-Paul

Me, too.  A lot of language questions are correctly
answered, Indistinguishable, to within the range
of subjective response.  This is NOT the case for
the readability and performance of Fortran and Python,
though; the differences are as massive as Jean-Paul
says.

HOWEVER, that's all true only in general.  As a new-
comer to both Fortran and Python, there's a fair
chance that the Fortran code you first produce would
be so suboptimal as to perform no better than the
corresponding Python.

My vote, therefore, is this:  unless you're in an
organization that provides a lot of Fortran support
to such beginners as yourself, choose Python.  It 
has all the pertinent advantages.

We can discuss secondary concerns at more length, 
if you wish:  Python's better suited than Fortran
for a range of other applications you might wish to
tackle some day; Python originated from a language-
for-beginners project, and truly is something you
can start to pick up in a day; your own scientific
specialty might be one that's particularly well-
endowed with an existing body of code written in
Fortran (or Python, or C++, or ...); and so on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python object overhead?

2007-03-26 Thread Matt Garman
On 3/23/07, Bjoern Schliessmann
[EMAIL PROTECTED] wrote:
 one blank line == EOF? That's strange. Intended?

In my case, I know my input data doesn't have any blank lines.
However, I'm glad you (and others) clarified the issue, because I
wasn't aware of the better methods for checking for EOF.

  Example 2: read lines into objects:
  # begin readobjects.py
  import sys, time
  class FileRecord:
  def __init__(self, line):
  self.line = line

 What's this class intended to do?

Store a line :)  I just wanted to post two runnable examples.  So the
above class's real intention is just to be a (contrived) example.

In the program I actually wrote, my class structure was a bit more
interesting.  After storing the input line, I'd then call split(|)
(to tokenize the line).  Each token would then be assigned to an
member variable.  Some of the member variables turned into ints or
floats as well.

My input data had three record types; all had a few common attributes.
 So I created a parent class and three child classes.

Also, many folks have suggested operating on only one line at a time
(i.e. not storing the whole data set).  Unfortunately, I'm constantly
looking forward and backward in the record set while I process the
data (i.e., to process any particular record, I sometimes need to know
the whole contents of the file).  (This is purchased proprietary
vendor data that needs to be converted into our own internal format.)

Finally, for what it's worth: the total run time memory requirements
of my program is roughly 20x the datafile size.  A 200MB file
literally requires 4GB of RAM to effectively process.  Note that, in
addition to the class structure I defined above, I also create two
caches of all the data (two dicts with different keys from the
collection of objects).  This is necessary to ensure the program runs
in a semi-reasonable amount of time.

Thanks to all for your input and suggestions.  I received many more
responses than I expected!

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


Re: Python object overhead?

2007-03-26 Thread Matt Garman
On 3/23/07, Jack Diederich [EMAIL PROTECTED] wrote:
 If you make the record a new style class (inherit from object) you can
 specify the __slots__ attribute on the class.  This eliminates the per
 instance dictionary overhead in exchange for less flexibility.

When you say new style class, do you mean that the __slots__ feature
is only available in a newer version of Python?  Unfortunately, I'm
stuck on 2.3.4 for this project.

Thanks,
Matt
-- 
http://mail.python.org/mailman/listinfo/python-list



calling class instances and their methods

2007-03-26 Thread spohle
hi,

i created an instance of a my own class which has methods and all. now
i get an outside function called, which is unfortunatly not aware of
the instace at all (i don't control how this outside function is
called). but i would like to get access back to my instance and it's
methods.

is there any clean way of doing this ?

thanks in advance

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


wx.grid problem

2007-03-26 Thread BH
Hi !

I have a small problem with wx.Grid and scrollbars.
Scrollbars definitively dissapears after resizing the frame.

Thx for help

#--
import wx,wx.grid
#--
class MainWindow(wx.Frame):
  def __init__(self,parent,id,title):
  wx.Frame.__init__(self,parent,wx.ID_ANY,title)
  #--
  self.grid= wx.grid.Grid(id=wx.ID_ANY,parent=self)
  self.grid.CreateGrid(numRows=10,numCols=2)
  self.grid.Fit()
  self.Fit()
  #--
  self.Show(1)
#--
app = wx.PySimpleApp()
frame=MainWindow(None,-1,'Grid sizer')
app.MainLoop()
del app
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Ramon Diaz-Uriarte
On 26 Mar 2007 06:20:32 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 OK...
 I've been told that Both Fortran and Python are easy to read, and are
 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level
 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??
 Thanks
 Chris


Dear Chris,

Why are you focusing on Python vs. Fortran? There might be other
choices out there you might want to consider, specifically C, O'Caml,
and Ada, since you mention number crunching. When choosing, you should
consider what other requirements you'll have; some people have hinted
at a few, such as portability (I am not saying fortrain ain't
portable) and rapid application development. Will you be doing lots of
string manipulation? Processing text-files? Gluing applications? What
do people around you use? What type of number crunching will you be
doing? Are the libraries available in any of the languages that you
are considering that do some/most of what you want to do? Are you
concernded about concurrent/distributed programming? Is this your
first programming language? Etc, etc, etc. In the end, maybe neither
Python nor Fortran might be the best choices for you.

HTH,

R.





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



-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python object overhead?

2007-03-26 Thread Jean-Paul Calderone
On Mon, 26 Mar 2007 09:13:58 -0600, Matt Garman [EMAIL PROTECTED] wrote:
On 3/23/07, Jack Diederich [EMAIL PROTECTED] wrote:
 If you make the record a new style class (inherit from object) you can
 specify the __slots__ attribute on the class.  This eliminates the per
 instance dictionary overhead in exchange for less flexibility.

When you say new style class, do you mean that the __slots__ feature
is only available in a newer version of Python?  Unfortunately, I'm
stuck on 2.3.4 for this project.

A new-style class is one which has a type of type instead of ClassType.
For example:

   class notnewstyle:
  ... pass
  ...
   type(notnewstyle)
  type 'classobj'
   class newstyle(object):
  ... pass
  ...
   type(newstyle)
  type 'type'
   class alsonewstyle(list):
  ... pass
  ...
   type(alsonewstyle)
  type 'type'
  

2.3 has new-style classes.

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Carl Banks
On Mar 26, 10:11 am, Andy Dingley [EMAIL PROTECTED] wrote:
 On 26 Mar, 14:20, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

  what are the advantages of using Python for
  creating number crunching apps over Fortran??

 If you have to ask, you've not experienced enough Fortran to know its
 sheer horror.

 You can write programs in Python that do usefully complicated things,
 and you can get them to work in a reasonable time. Fortran can't do
 this, for anything more than the trivial. Classic Fortran tasks of
 the past are now seen as trivial. OK, so they did it to a lot of data,
 but they really didn't do anything very complex to it.

You couldn't be more incorrect.  I have run some very old (pre-Fortran
77) programs that are very far from trivial.

 You can also write Python that other people can read and maintain. You
 can't do this in Fortran, without a truly insane amount of trouble.

This is a lie.  I've seen some Fortran code that was hellspawned, and
some that was clear as glass.  The latter came about without a truly
insane amount of trouble.

 As
 Fortran programs have historically been authored and hacked on by
 successive generations of grad students, this is the most vital
 feature of all.

Perhaps this is your impression because it's the only Fortran code
you've ever been exposed to?

 Finally we're no longer so interested in number crunching. Number
 crunching used to consist of simple operations over vast arrays of
 data, although this was data with remarkably simple structure by
 today's standards. These just aren't the major class of problems of
 interest today.

I suspect you're speaking from a narrow perspective, because number
crunching, as you define it, is still a problem of interest and
heavily researched.  Maybe it's not in your field.  Anyways, you seem
to be ignorant of the complexities of simple operations over vast
arrays, as if it you could accomplish these operations with a few
lines of Python and numpy.  That might be true for your homework, but
good number-crunching codes often did a lot of stuff under the covers.

 There's a massive difference between old-school FEA
 (bashing Newton and Hooke into tinier and tinier cells) and
 bioinformatics or anything involving the representation of big data
 graphs.

Ok, but exactly how do bioinformatics or big data graphs help you
determine the stress profile in a beam?

  Python is a tad slower than Fortran

 If the Fortran program turns out to have been broken all along, then
 who cares?

That Fortran code is inherently broken is a pretty asinine thing to
suggest.  No one's under the impression that Fortran is a great, all-
purpose language like Python is, but it does what it was designed to
do well.  When faced with a numerical problem, it's reasonable to
consider using Fortran (especially knowing you can interface it with
Python).


Carl Banks

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


Re: Python object overhead?

2007-03-26 Thread Gabriel Genellina
On Mar 26, 12:13 pm, Matt Garman [EMAIL PROTECTED] wrote:
 On 3/23/07, Jack Diederich [EMAIL PROTECTED] wrote:

  If you make the record a new style class (inherit from object) you can
  specify the __slots__ attribute on the class.  This eliminates the per
  instance dictionary overhead in exchange for less flexibility.

 When you say new style class, do you mean that the __slots__ feature
 is only available in a newer version of Python?  Unfortunately, I'm
 stuck on 2.3.4 for this project.

new style classes are available since Python 2.2. You declare a new-
style class just by inheriting from object. Among other things, they
have properties, and the above menctioned __slots__ optimization.


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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread sturlamolden
On Mar 26, 3:20 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 I've been told that Both Fortran and Python are easy to read, and are
 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level
 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??

Fortran may be faster, but Python (with NumPy and SciPy) is often fast
enough. A lot of practitioners use Matlab, which is often slower than
Python. Matplotlib is an excellent Python extension for graphing
data.

Anyone serious about numerical computing should learn Fortran 95. But
use it sparsely and only where its needed. Fortran is perfect for
numerical work but useless for anything else. Usually the amount of
code that will benefit from using Fortran over NumPy makes up less
than a percent of the line count. You can call Fortran from Python
using f2py, so you can get the best from both worlds.







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


Re: calling class instances and their methods

2007-03-26 Thread Gabriel Genellina
On Mar 26, 12:00 pm, spohle [EMAIL PROTECTED] wrote:

 i created an instance of a my own class which has methods and all. now
 i get an outside function called, which is unfortunatly not aware of
 the instace at all (i don't control how this outside function is
 called). but i would like to get access back to my instance and it's
 methods.

I don't understand well. Do you want to call a method on your object,
from inside that external function? Can you modify its code?

--
Gabriel Genellina

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


PMW widget - skip tabbing to it

2007-03-26 Thread jp
I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
I skip over these widgets when using the tab key?

Thank you,
John

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


Kill thread or at least socket.getaddrinfo

2007-03-26 Thread Thomas Dybdahl Ahle
Hi, I'm writing an application that connects to the internet.
Something like this:

for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
self.sock = socket.socket(af, socktype, proto)

Now if the user press the cancel button, I'd like the connection to 
imidiatly stop. I run
self.sock.shutdown(socket.SHUT_RDWR)
self.sock.close()
Dunno if they are both nessesary. I normaly use only the first, but it 
makes no difference to use both.

If python is at the actual connection in socket.socket( this work fine, 
but if python is at calling socket.getaddrinfo(, it doesn't stop.

I also can't kill the thread, as it is afaik not a possibility in python.
Is there any other way to do this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling class instances and their methods

2007-03-26 Thread Erik Johnson
spohle [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 hi,

 i created an instance of a my own class which has methods and all. now
 i get an outside function called, which is unfortunatly not aware of
 the instace at all (i don't control how this outside function is
 called). but i would like to get access back to my instance and it's
 methods.

 is there any clean way of doing this ?

 thanks in advance


Ummm...  I'm not exactly sure what you mean by an outside function, but
let's refer to that function as f(). Are you saying you want to re-implement
f() to use your new object but don't want to (or can't) change calls to f()?

If so, then you can either use a global reference to your new object if
it is the sort of thing you want to keep around between invocations of f()
(i.e., create your object somewhere and then save in a scope that f() can
access). Otherwise, you can simply instantiate your object inside of f() as
a local variable and use it.

If you mean something else, I guess you will have to clarify.


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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 On Mar 26, 8:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 OK...
 I've been told that Both Fortran and Python are easy to read, and are
 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level
 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??
 Thanks
 Chris
 
 While I have never personally dealt with Fortran, I looked it up here:
 
 http://en.wikipedia.org/wiki/Fortran_code_examples
 
 The code examples speak for themselves. I recommend you look those
 over and then look over similar simple program written in Python.
 Python is still easier to read. Fortran also appears to be a compiled
 language, whereas Python is an interpreted language.

Being 'compiled' or 'interpreted' is not a feature of a language, but of 
a given implementation of a language (and even then, some 
implementations of some languages supports both).

wrt/ CPython (the reference implementation), it is actually compiled to 
byte-code - just like Java. The main difference being that the VM is 
smart enough to automagically (re)compile what's needed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx.grid problem

2007-03-26 Thread kyosohma
On Mar 26, 10:20 am, BH [EMAIL PROTECTED] wrote:
 Hi !

 I have a small problem with wx.Grid and scrollbars.
 Scrollbars definitively dissapears after resizing the frame.

 Thx for help

 #--
 import wx,wx.grid
 #--
 class MainWindow(wx.Frame):
   def __init__(self,parent,id,title):
   wx.Frame.__init__(self,parent,wx.ID_ANY,title)
   #--
   self.grid= wx.grid.Grid(id=wx.ID_ANY,parent=self)
   self.grid.CreateGrid(numRows=10,numCols=2)
   self.grid.Fit()
   self.Fit()
   #--
   self.Show(1)
 #--
 app = wx.PySimpleApp()
 frame=MainWindow(None,-1,'Grid sizer')
 app.MainLoop()
 del app

If I understand this correctly, that is normal. Your grid is only two
columns by 10 rows, so if you resize your frame so that it shows all
rows and columns, the scroll bars will disappear, much like other
apps, such as FireFox. If you enlarge the frame enough, the scrollbars
go away.

Mike

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Cameron Laird
In article [EMAIL PROTECTED],
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
.
.
.
 You can get the speed of fortran in Python by using libraries like
 Numeric without losing the readability of Python.


Can you back this up with some source??
Chris


Yes.

While evidence in computing science is ... well, the standards aren't
well established; still, I think you'll want to start with URL:
http://www.sciencemag.org/cgi/content/abstract/279/5356/1525 .  This
describes a supercomputer simulation that won awards in the '90s for
its performance.  The application itself is basically what Jean-Paul
recommended:  Python, with high-performance libraries written in C,
C++, and Fortran.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Cameron Laird
In article [EMAIL PROTECTED],
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
.
.
.
Is there a mac version??
Thanks
Chris


Yes.

Several, in fact--all available at no charge.  The Python
world is different from what experience with Fortran might
lead you to expect.

I'll be more clear:  Fortran itself is a distinguished
language with many meritorious implementations.  It can be
costly, though, finding the implementation you want/need
for any specific environment.

Python, in contrast, is blessed with a plethora of 
implementations and variations, all of which are available
without licensing fee.  In particular, recent Mac OS X
installations INCLUDE Python--it's already in there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Cameron Laird
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
   ...
  So I'ld suggest to start with downloading the Enthought edition of Python,
  and you can judge for yourself within 10 minutes,
  if it's fast enough.
 
  cheers,
  Stef Mientki
 
 Is there a mac version??

http://download.enthought.com/MacEnthon/ReadMe.html but it's self
labeled as 0.1 Test Release i.e. somewhat preliminary; it claims to
support only Panther (10.3) and its 2.3.0 Python (no claims for Tiger,
10.4, and its 2.3.5 Python, nor for other Python Mac istalls yet).

If you're just trying to learn and check things out, it might be better
to get a more recent Python from python.org (2.5 or 2.4.4) and the
various other packages as and when you need them (you can use the
MacEnthon list as a guide:-).  You'll need a C compiler to be sure you
can install any package from sources -- Apple's XCode includes gcc, it's
free, and it's the safest choice (but it's a HUGE download, as it comes
with a lot of stuff -- I don't think Apple offers a simple way to
install just gcc and minimal supporting tools).


Alex

Yes and no.  Alex, while useful scientific computing under Mac OS X
will almost certainly eventually involve installation of XCode and
so on, Nomad.C can start to learn Python without a need to install
ANYTHING.  As you know, Python is already there, and the version that
comes with 10.4 (2.3.5, as nearly as I can easily tell) is easily 
adequate to take him through the Tutorial (with minor exceptions).

Also, while I, like you, am aware of no minimal-gcc package from
Apple, I think third parties make it available.  However, I'm not
motivated enough at this point to track down the details.  I think
Nomad.C should start with what he has under 10.4, and plan to move
on later to all of XCode.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: call to function by text variable

2007-03-26 Thread Cameron Laird
In article [EMAIL PROTECTED],
Steve Holden  [EMAIL PROTECTED] wrote:
Cameron Laird wrote:
 In article [EMAIL PROTECTED],
 Jan Schilleman [EMAIL PROTECTED] wrote:
 Hi,

 try this:
 func = getattr(operations, [Replace, ChangeCase, Move][n])

 HTH,
 Jan

 ianaré [EMAIL PROTECTED] schreef in bericht 
 news:[EMAIL PROTECTED]
 yeah the subject doesn't really make sense does it?

 anyway want I want to do is this:
 if n == 1:

self.operations.insert(pos, operations.Replace.Panel(self, main))
  .
  .
  .
 I think you meant ...[n - 1] rather than ...[n].
 
 I'm a tiny bit surprised no one has organized this in terms
 of a dictionary.  I don't know, of course, how robust is the
 characterization of n as a small integer.  Maybe
 
   lookup_table = {
   0: Replace,
   1: ChangeCase,
   2: Move}
 
 captures the sentiment; maybe something else does it better.
 
Surely for this requirement the *only* advantage of a dictionary over a 
list is its ability to index with arbitrary values and thereby avoid the 
need to use [n-1]. Wouldn't it therefore be less perverse to use

 lookup_table = {
   1: Replace,
   2: ChangeCase,
   3: Move}

Of course the dictionary would be a big win if the integer choice values 
weren't a linear sequence. Otherwise using a list with a fixed offset is 
likely to be quicker.
.
.
.
Ugh.  Yes.

Maybe your question, Wouldn't it therefore be less perverse ...?,
was rhetorical.  I feel obliged to answer in public, though, rather
than sending the private e-mail I originally wrote, because I want
to leave no doubt in the minds of readers of this thread:  what I
wrote was wrong.  Yes, Steve's lookup_table binding (or assignment)
was what I had in mind all along, and entirely superior to what I
mistakenly wrote; my thanks to him.  He also elaborated the correct
detail:  if the integer choice values weren't a linear sequence,
or if they weren't even integers, or ..., then the dictionary
suddenly becomes much more compelling.

Incidentally, a fair amount of Python code that looks like

if n == 1:
...
elif n == 2:
...

turns out, in my experience, to have been inherited from some other
language in such a way that it turns out n is not even the most 
natural or expressive determinant.  A fully idiomatic rewriting will
have a table where the keys are more-humanly-readable strings, rather
than small integers.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Kill thread or at least socket.getaddrinfo

2007-03-26 Thread kyosohma
On Mar 26, 10:53 am, Thomas Dybdahl Ahle [EMAIL PROTECTED] wrote:
 Hi, I'm writing an application that connects to the internet.
 Something like this:

 for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
 af, socktype, proto, canonname, sa = res
 try:
 self.sock = socket.socket(af, socktype, proto)

 Now if the user press the cancel button, I'd like the connection to
 imidiatly stop. I run
 self.sock.shutdown(socket.SHUT_RDWR)
 self.sock.close()
 Dunno if they are both nessesary. I normaly use only the first, but it
 makes no difference to use both.

 If python is at the actual connection in socket.socket( this work fine,
 but if python is at calling socket.getaddrinfo(, it doesn't stop.

 I also can't kill the thread, as it is afaik not a possibility in python.
 Is there any other way to do this?


This is addressed to some degree on a wxPython wiki at:

http://wiki.wxpython.org/index.cgi/LongRunningTasks

I think you can also use the join() method. I've also heard that if
you know the pid, you can kill it, but that's not always a clean way
of accomplishing the task.

Mike

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


Re: How to find tag to /tag HTML strings and 'save' them?

2007-03-26 Thread Max Erickson
John Nagle [EMAIL PROTECTED] wrote:

 htags = soup.findAll({'h2':True, 'H2' : True}) # get all H2 tags,
 both cases 

Have you been bitten by this? When I read this, I was operating under 
the assumption that BeautifulSoup wasn't case sensitive, and then I 
tried this:

 import BeautifulSoup as BS

 soup=BS.BeautifulSoup('bone/bBtwo/B')
 soup.findAll('b')
[bone/b, btwo/b]
 soup.findAll({'b':True})
[bone/b, btwo/b]
 

So I am a little curious.


max

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


Re: Python object overhead?

2007-03-26 Thread Bruno Desthuilliers
Matt Garman a écrit :
(snip)
 Also, many folks have suggested operating on only one line at a time
 (i.e. not storing the whole data set).  Unfortunately, I'm constantly
 looking forward and backward in the record set while I process the
 data (i.e., to process any particular record, I sometimes need to know
 the whole contents of the file).  (This is purchased proprietary
 vendor data that needs to be converted into our own internal format.)

Don't know if this could solve your problem, but have considered using 
an intermediate (preferably embedded) SQL database (something like 
SQLite) ?

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


Re: functions, classes, bound, unbound?

2007-03-26 Thread 7stud
On Mar 25, 3:09 pm, Steven Bethard [EMAIL PROTECTED] wrote:
 Here's another way of looking at it::

   class Test(object):
  ... pass
  ...
   def greet():
  ... print 'Hello'
  ...
 Test.greet = greet
 Test.greet
   unbound method Test.greet

Interesting.  After playing around with that example a bit and finally
thinking I understood bound v. unbound, I found what appears to be an
anomaly:

class Test(object):
pass

def greet(x):
print hello

Test.func = greet
print Test.func

t = Test()
print t.func

def sayBye(x):
print bye

t.bye = sayBye
print t.bye
output:
unbound method Test.greet
bound method Test.greet of __main__.Test object at 0x6dc50
function sayBye at 0x624b0

Why doesn't t.bye cause a method object to be created?


 ... under the covers, classes are actually using
 doing something like this::

   Test.__dict__['greet'].__get__(None, Test)
  unbound method Test.greet
   Test.greet == Test.__dict__['greet'].__get__(None, Test)
  True


...via __getattribute_, right?

 ... if you want to get a method from a function, you can always do that
 manually yourself::

   greet.__get__(None, Test)
  unbound method Test.greet

Manually creating a method object.  Nice.

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


Re: PMW widget - skip tabbing to it

2007-03-26 Thread kyosohma
On Mar 26, 10:51 am, jp [EMAIL PROTECTED] wrote:
 I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
 I skip over these widgets when using the tab key?

 Thank you,
 John

I would probably write some custom event handling. Something that
could tell it was a key-press event and not just an on-focus event.
Then it would be a simple, if key-press == tab, put focus on next
widget of interest. Something like that should work.

Mike

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Robert Kern
Alex Martelli wrote:
 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
...
 So I'ld suggest to start with downloading the Enthought edition of Python,
 and you can judge for yourself within 10 minutes,
 if it's fast enough.

 cheers,
 Stef Mientki
 Is there a mac version??
 
 http://download.enthought.com/MacEnthon/ReadMe.html but it's self
 labeled as 0.1 Test Release i.e. somewhat preliminary; it claims to
 support only Panther (10.3) and its 2.3.0 Python (no claims for Tiger,
 10.4, and its 2.3.5 Python, nor for other Python Mac istalls yet).

It no longer exists, in fact. I don't know why the readme still exists, too.

 If you're just trying to learn and check things out, it might be better
 to get a more recent Python from python.org (2.5 or 2.4.4) and the
 various other packages as and when you need them (you can use the
 MacEnthon list as a guide:-).  You'll need a C compiler to be sure you
 can install any package from sources -- Apple's XCode includes gcc, it's
 free, and it's the safest choice (but it's a HUGE download, as it comes
 with a lot of stuff -- I don't think Apple offers a simple way to
 install just gcc and minimal supporting tools).

Here are some more instructions for building the usual suspects: numpy, scipy,
VTK, PIL, ipython, matplotlib.

  https://svn.enthought.com/enthought/wiki/IntelMacPython25

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: PMW widget - skip tabbing to it

2007-03-26 Thread kyosohma
On Mar 26, 11:17 am, [EMAIL PROTECTED] wrote:
 On Mar 26, 10:51 am, jp [EMAIL PROTECTED] wrote:

  I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
  I skip over these widgets when using the tab key?

  Thank you,
  John

 I would probably write some custom event handling. Something that
 could tell it was a key-press event and not just an on-focus event.
 Then it would be a simple, if key-press == tab, put focus on next
 widget of interest. Something like that should work.

 Mike

I looked in my Tkinter book, and it says that if the widget has the
takefocus option set to true, the widget is placed in the tab group
and will get focus when they are tabbed to. I assume that this means
if you set the PMW widgets' takefocus option to false, they will be
skipped over since they won't be in the tab group.

Mike

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


Re: PMW widget - skip tabbing to it

2007-03-26 Thread jp
On Mar 26, 11:17 am, [EMAIL PROTECTED] wrote:
 On Mar 26, 10:51 am, jp [EMAIL PROTECTED] wrote:

  I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
  I skip over these widgets when using the tab key?

  Thank you,
  John

 I would probably write some custom event handling. Something that
 could tell it was a key-press event and not just an on-focus event.
 Then it would be a simple, if key-press == tab, put focus on next
 widget of interest. Something like that should work.

 Mike


Isn't there just a simple configuration option to disable the tab
key?  Like the takfocus option with Tkinter widgets?

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


Re: wx.grid problem

2007-03-26 Thread BH
Yes, absolutely, but try to minimize it, and the scrollbars stays hidden !!!


[EMAIL PROTECTED] a écrit :
 On Mar 26, 10:20 am, BH [EMAIL PROTECTED] wrote:
 Hi !

 I have a small problem with wx.Grid and scrollbars.
 Scrollbars definitively dissapears after resizing the frame.

 Thx for help

 #--
 import wx,wx.grid
 #--
 class MainWindow(wx.Frame):
   def __init__(self,parent,id,title):
   wx.Frame.__init__(self,parent,wx.ID_ANY,title)
   #--
   self.grid= wx.grid.Grid(id=wx.ID_ANY,parent=self)
   self.grid.CreateGrid(numRows=10,numCols=2)
   self.grid.Fit()
   self.Fit()
   #--
   self.Show(1)
 #--
 app = wx.PySimpleApp()
 frame=MainWindow(None,-1,'Grid sizer')
 app.MainLoop()
 del app
 
 If I understand this correctly, that is normal. Your grid is only two
 columns by 10 rows, so if you resize your frame so that it shows all
 rows and columns, the scroll bars will disappear, much like other
 apps, such as FireFox. If you enlarge the frame enough, the scrollbars
 go away.
 
 Mike
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PMW widget - skip tabbing to it

2007-03-26 Thread jp
On Mar 26, 11:27 am, [EMAIL PROTECTED] wrote:
 On Mar 26, 11:17 am, [EMAIL PROTECTED] wrote:

  On Mar 26, 10:51 am, jp [EMAIL PROTECTED] wrote:

   I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
   I skip over these widgets when using the tab key?

   Thank you,
   John

  I would probably write some custom event handling. Something that
  could tell it was a key-press event and not just an on-focus event.
  Then it would be a simple, if key-press == tab, put focus on next
#  widget of interest. Something like that should work.

  Mike

 I looked in my Tkinter book, and it says that if the widget has the
 takefocus option set to true, the widget is placed in the tab group
 and will get focus when they are tabbed to. I assume that this means
 if you set the PMW widgets' takefocus option to false, they will be
 skipped over since they won't be in the tab group.

 Mike

I've tried using the takefocus option set to 0 and 1 but either way,
the tab key still stops at my EntryField.  Below is my snippet of
code.  What am I doing wrong?

entry=Pmw.EntryField(frame,
 labelpos = 'w',
 value = ,
 label_text =
'Name:')
entry.grid(row=1)
#entry.component('entry').takefocus = 1
entry.component('entry').takefocus = 0

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


Re: functions, classes, bound, unbound?

2007-03-26 Thread irstas
On Mar 26, 7:15 pm, 7stud [EMAIL PROTECTED] wrote:
 On Mar 25, 3:09 pm, Steven Bethard [EMAIL PROTECTED] wrote:

  Here's another way of looking at it::

class Test(object):
   ... pass
   ...
def greet():
   ... print 'Hello'
   ...
  Test.greet = greet
  Test.greet
unbound method Test.greet

 Interesting.  After playing around with that example a bit and finally
 thinking I understood bound v. unbound, I found what appears to be an
 anomaly:
 
 class Test(object):
 pass

 def greet(x):
 print hello

 Test.func = greet
 print Test.func

 t = Test()
 print t.func

 def sayBye(x):
 print bye

 t.bye = sayBye
 print t.bye
 output:
 unbound method Test.greet
 bound method Test.greet of __main__.Test object at 0x6dc50
 function sayBye at 0x624b0

 Why doesn't t.bye cause a method object to be created?

Because that would be bad and unexpected behaviour. I might want to
store callback functions to an object as attributes. It wouldn't make
sense for the functions to be bound to the container object when I'd
access them.

Of course, Test.func = greet; print Test.func is also unexpected
behaviour as Test.func is not same as Test.__dict__['func']. But it's
unexpected in a good way, because it facilitates the way classes are
usually used. The whole point of the magic is to make common idioms
simple.

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


Re: functions, classes, bound, unbound?

2007-03-26 Thread 7stud
On Mar 26, 5:08 am, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
 Most of Python's object model is documented here:

 http://www.python.org/download/releases/2.2.3/descrintro/http://users.rcn.com/python/download/Descriptor.htm


Thanks.  I've looked at both of those, and the second one is very
good.

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Carl Banks
On Mar 26, 9:42 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On 26 Mar 2007 06:20:32 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 OK...
 I've been told that Both Fortran and Python are easy to read, and are

 Python is hugely easier to read.

 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level

 Fortran is massively faster than Python.

 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??

 You can get the speed of fortran in Python by using libraries like
 Numeric without losing the readability of Python.

This is true only for problems that can take advantage of scalability,
which is a large and important subset of all numerical problems, but
is still only a subset.

Some problems (e.g., simulation) require repeated sequential
evaluation of formulas.  For other problems (e.g., collision
detection) the operands change rapidly.  The scalability of numpy
doesn't help so much here.

(Anecdote: I once did a collision detection using Numeric.  It would
take slices out of the data set as it narrowed down the possible
collisions.  It actually worked pretty well.  But the slicing was
crazy and hard to follow.  I rewrote it in C and it was both faster
and more readable.)


Carl Banks

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Erik Johnson

[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 OK...
 I've been told that Both Fortran and Python are easy to read, and are
 quite useful in creating scientific apps for the number crunching, but
 then Python is a tad slower than Fortran because of its a high level
 language nature, so what are the advantages of using Python for
 creating number crunching apps over Fortran??
 Thanks
 Chris

So, after reading much of animated debate here, I think few would
suggest that Python is going to be faster than FORTRAN when it comes to raw
execution speed. Numeric and SciPy are Python modules that are geared
towards numerical computing and can give substantial performance gians over
plain Python.

A reasonable approach (which has already been hinted at here), is to try
to have the best of both world by mixing Python and FORTRAN - doing most of
the logic and support code in Python and writing the raw computing routines
in FORTRAN. A reasonable approach might be to simply make your application
work in Python, then use profiling to identify what parts are slowest and
move those parts into a complied language such as FORTRAN or C if overall
performance is not fast enough.  Unless your number crunching project is
truly massive, you may find that Python is a lot faster than you thought and
may be plenty fast enough on it's own.

So, there is a tradeoff of resources between development time, execution
time, readability, understandability, maintainability, etc.

psyco is a module I haven't seen mentioned here - I don't know a lot
about it, but have seen substantial increases in performance in what little
I have used it. My understanding is that it produces multiple versions of
functions tuned to particular data types, thus gaining some advantage over
the default, untyped bytecode Python would normally produce. You can think
of it as a JIT compiler for Python (but that's not quite what it is doing).
The home page for that module is here:  http://psyco.sourceforge.net/

Hope that help,
-ej


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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread [EMAIL PROTECTED]
On 26 Mar, 17:59, Erik Johnson [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]

  OK...
  I've been told that Both Fortran and Python are easy to read, and are
  quite useful in creating scientific apps for the number crunching, but
  then Python is a tad slower than Fortran because of its a high level
  language nature, so what are the advantages of using Python for
  creating number crunching apps over Fortran??
  Thanks
  Chris

 So, after reading much of animated debate here, I think few would
 suggest that Python is going to be faster than FORTRAN when it comes to raw
 execution speed. Numeric and SciPy are Python modules that are geared
 towards numerical computing and can give substantial performance gians over
 plain Python.

 A reasonable approach (which has already been hinted at here), is to try
 to have the best of both world by mixing Python and FORTRAN - doing most of
 the logic and support code in Python and writing the raw computing routines
 in FORTRAN. A reasonable approach might be to simply make your application
 work in Python, then use profiling to identify what parts are slowest and
 move those parts into a complied language such as FORTRAN or C if overall
 performance is not fast enough.  Unless your number crunching project is
 truly massive, you may find that Python is a lot faster than you thought and
 may be plenty fast enough on it's own.

 So, there is a tradeoff of resources between development time, execution
 time, readability, understandability, maintainability, etc.

 psyco is a module I haven't seen mentioned here - I don't know a lot
 about it, but have seen substantial increases in performance in what little
 I have used it. My understanding is that it produces multiple versions of
 functions tuned to particular data types, thus gaining some advantage over
 the default, untyped bytecode Python would normally produce. You can think
 of it as a JIT compiler for Python (but that's not quite what it is doing).
 The home page for that module is here:  http://psyco.sourceforge.net/

 Hope that help,
 -ej

Ok
Thanks you all for giving a little insight into what Python can
actually do, I think I've read enough to convince me that Python is
generally a very flexible, fast, powerful language that can be used in
a wide variety of applications instead of focusing on numerical
functions like fortran does.
Thanks again!

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


how to abort on syntax errors

2007-03-26 Thread Josh
I have a lot of except Exception, e statements in my code, which poses some 
problems. One of the biggest is whenever I refactor even the triviallest 
thing in my code.

I would like python to abort, almost as if it were a compile-time error, 
whenever it cannot find a function, or if I introduced a syntax error. But, 
instead, it merrily proceeds on its way.

Is there some idiom that you use in situations like these?
thanks,
josh


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


fetch html page via isa proxy

2007-03-26 Thread Radek
Hi,

I have been trying several days to get the html page of www.python.org
when behind the corporate MS isa proxy.

I have tried setting http_proxy environment, played with proxy
openers, use ntlm proxy server all without success.

I can get the page using Firefox and IE with proxy settings.

As the last resort I started to play with pywin32 win32inet, but even
the test_win32inet.py does not get there.

Any advice? Or better working example?

Thanks a lot,

Radek

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


Re: PMW widget - skip tabbing to it

2007-03-26 Thread kyosohma
On Mar 26, 11:35 am, jp [EMAIL PROTECTED] wrote:
 On Mar 26, 11:27 am, [EMAIL PROTECTED] wrote: On Mar 26, 11:17 am, [EMAIL 
 PROTECTED] wrote:

   On Mar 26, 10:51 am, jp [EMAIL PROTECTED] wrote:

I have multiple PMW widgets (EntryFields, ScrolledField etc), how can
I skip over these widgets when using the tab key?

Thank you,
John

   I would probably write some custom event handling. Something that
   could tell it was a key-press event and not just an on-focus event.
   Then it would be a simple, if key-press == tab, put focus on next

 #  widget of interest. Something like that should work.



   Mike

  I looked in my Tkinter book, and it says that if the widget has the
  takefocus option set to true, the widget is placed in the tab group
  and will get focus when they are tabbed to. I assume that this means
  if you set the PMW widgets' takefocus option to false, they will be
  skipped over since they won't be in the tab group.

  Mike

 I've tried using the takefocus option set to 0 and 1 but either way,
 the tab key still stops at my EntryField.  Below is my snippet of
 code.  What am I doing wrong?

 entry=Pmw.EntryField(frame,
  labelpos = 'w',
  value = ,
  label_text =
 'Name:')
 entry.grid(row=1)
 #entry.component('entry').takefocus = 1
 entry.component('entry').takefocus = 0

According to the Tkinter book, setting takefocus to 0 (false) should
work. Are you putting th EntryField into a Grid? If so, that might be
the problem. I suppose the grid may override its children's settings.

I've never messed too much with skipping widgets in the tab order. You
could pack the PMW widgets last so that they won't get tabbed to until
the end.

There's also tk_focusNext  tk_focusPrev. See the following post for
more info and ideas:

http://www.dbforums.com/archive/index.php/t-1377788.html

Mike

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


Re: Python object overhead?

2007-03-26 Thread 7stud
On Mar 26, 9:13 am, Matt Garman [EMAIL PROTECTED] wrote:
 On 3/23/07, Jack Diederich [EMAIL PROTECTED] wrote:

  If you make the record a new style class (inherit from object) you can
  specify the __slots__ attribute on the class.  This eliminates the per
  instance dictionary overhead in exchange for less flexibility.

 When you say new style class, do you mean that the __slots__ feature
 is only available in a newer version of Python?  Unfortunately, I'm
 stuck on 2.3.4 for this project.


__slots__ were made available in 2.2 according to GvR's tutorial here:

http://www.python.org/download/releases/2.2.3/descrintro/

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


Re: how to abort on syntax errors

2007-03-26 Thread kyosohma
On Mar 26, 12:21 pm, Josh [EMAIL PROTECTED] wrote:
 I have a lot of except Exception, e statements in my code, which poses some
 problems. One of the biggest is whenever I refactor even the triviallest
 thing in my code.

 I would like python to abort, almost as if it were a compile-time error,
 whenever it cannot find a function, or if I introduced a syntax error. But,
 instead, it merrily proceeds on its way.

 Is there some idiom that you use in situations like these?
 thanks,
 josh

Try sticking in an

try:
  #do something
except SyntaxError, e:
   print e
   sys.exit(0)
except Exception, e:
   print e


# You put in as many exceptions as you like.

Mike

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


Re: how to abort on syntax errors

2007-03-26 Thread skip

Josh I have a lot of except Exception, e statements in my code, which
Josh poses some problems. One of the biggest is whenever I refactor
Josh even the triviallest thing in my code.

Josh I would like python to abort, almost as if it were a compile-time
Josh error, whenever it cannot find a function, or if I introduced a
Josh syntax error. But, instead, it merrily proceeds on its way.

Josh Is there some idiom that you use in situations like these?

In general, I think you should be more specific in the exceptions you
catch.  For example, if you want to look up a key in a dictionary and most
of the time it's there, but every now and again you need to add it, I'd use
something like this:

try:
val = somedict[key]
except KeyError:
# need to initialize slot
somedict[key] = INITIAL_VALUE

That is, be as precise as you can in the exceptions you catch.  Also, try to
keep the body of the try block as small as you can.

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


Re: how to abort on syntax errors

2007-03-26 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Josh wrote:

 I have a lot of except Exception, e statements in my code, which poses some 
 problems. One of the biggest is whenever I refactor even the triviallest 
 thing in my code.
 
 I would like python to abort, almost as if it were a compile-time error, 
 whenever it cannot find a function, or if I introduced a syntax error. But, 
 instead, it merrily proceeds on its way.
 
 Is there some idiom that you use in situations like these?

Just don't use so many ``except Exception:`` constructs that obviously
swallow exceptions they shouldn't swallow.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to abort on syntax errors

2007-03-26 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 On Mar 26, 12:21 pm, Josh [EMAIL PROTECTED] wrote:
 I have a lot of except Exception, e statements in my code, which poses some
 problems. One of the biggest is whenever I refactor even the triviallest
 thing in my code.

 I would like python to abort, almost as if it were a compile-time error,
 whenever it cannot find a function, or if I introduced a syntax error. But,
 instead, it merrily proceeds on its way.

 Is there some idiom that you use in situations like these?
 thanks,
 josh
 
 Try sticking in an
 
 try:
   #do something
 except SyntaxError, e:
print e
sys.exit(0)
 except Exception, e:
print e
 
 
 # You put in as many exceptions as you like.
 
Of course the main problem with this solution is that a piece of code 
will raise a syntax error when it's compiled (i.e. at module import 
time, or when the main program starts up). So in the case where #do 
something has a syntax error it won;t be trapped because the program 
hasn't got to execution by the time the error is detected.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings   http://holdenweb.blogspot.com

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


  1   2   >