[FAQTS] Python Knowledge Base Update -- August 22nd, 2000

Fiona Czuczman fiona at sitegnome.com
Tue Aug 22 18:19:23 EDT 2000


Hi Guys,

Thanks to all that responded to my call yesterday.  We managed to get a 
number of the unanswered questions answered.

regards,

Fiona Czuczman


## Edited Entries ##############################################


-------------------------------------------------------------
What advantages does PyApache give over simple Python scripting?
http://www.faqts.com/knowledge-base/view.phtml/aid/1666
-------------------------------------------------------------
Steve Holden, Fiona Czuczman
Alex Martelli

Just like mod_python, mod_perl, etc:

1. performance (no interpreter startup cost at every request)
2. ability to implement in Python, not just response handlers,
    but all sort of handlers that Apache let you set (authentication,
    logging, etc, etc).


-------------------------------------------------------------
Can I make something like jtable with tkinter?
http://www.faqts.com/knowledge-base/view.phtml/aid/4019
-------------------------------------------------------------
udo apolloner, Fiona Czuczman
Richard Chamberlain

A jTable is a very powerful widget enabling you to have graphics and
text in each cell. At the moment there isn't anything like that in Tk.
The closest you would come is if you created a window filled with
canvases, or just entries if you were only interested in text. You would
find an issue with the number of widgets and speed, so you would have to
find a way to only display those widgets that were currently onscreen.
All in all not very practical. Two solutions spring to mind, (a) use
wxPython they have a nice wxGrid control or (b) See what the next
release of either tcl/tk brings.


-------------------------------------------------------------
When I start Python 1.5.2, I get the error: Built-in exception class not found: EnvironmentError.  Library mismatch?"  Any ideas on solving this?
http://www.faqts.com/knowledge-base/view.phtml/aid/5294
-------------------------------------------------------------
Michele Chen, Fiona Czuczman
Michael Dyck

I got this message just yesterday when I tried to run my newly-
installed Python 1.6b1 (except that the missing exception class was
"UnboundLocalError" rather than "EnvironmentError").

The problem was that my autoexec.bat file was still initializing
environment variables [not sure what the proper Windows term is]
for Python 1.5.2. (I think PYTHONPATH was the main culprit.)

So if you're on Windows, I suggest looking in C:\AUTOEXEC.BAT for
references to a previous Python installation, and either remove them,
or comment them out with a "rem". I think you'll have to restart
Windows for it to take effect.

If you're on Unix, you might be setting PYTHON* variables in your shell
start-up file (~/.cshrc, ~/.bashrc, etc). Remove them, or comment
them out with a "#".


-------------------------------------------------------------
>From within a function, is there a way to determine what the parent of a calling widget is?
http://www.faqts.com/knowledge-base/view.phtml/aid/5320
-------------------------------------------------------------
Mark Tipton, Fiona Czuczman
Richard Chamberlain

from Tkinter import *
root=Tk()
frame=Frame(root)
button=Button(frame,text='Click Me')
button.pack()
frame.pack(fill=BOTH,expand=1)
def clicker(event):
    event.widget.master.configure(bg='blue')
button.bind('<Button>',clicker)
root.mainloop()

If you bind an event you have access to the calling widget via 
event.widget, so you have access to the calling widget's parent via 
event.widget.master.


-------------------------------------------------------------
How should a sortable sequence be implemented?
Keyed Tree as sorted sequence:  Slice & Key access?
http://www.faqts.com/knowledge-base/view.phtml/aid/5367
-------------------------------------------------------------
Charles Hixson, Fiona Czuczman
Will Ware

Objects can be sorted as long as they can be compared. Fundamental
types (ints, floats, strings) can be compared with the globally defined
cmp() function. cmp(x,y) returns a negative integer if x<y, zero if 
x==y, and a positive integer if x>y. If the 'sort' method is called on a 
list of objects, the list will be sorted in increasing order:

x = [3,1,4,1,5,9,2,6]
x.sort()
print x  -->  [1,1,2,3,4,5,6,9]

Classes can be made sortable by defining a __cmp__ method for them. For
example, to sort a list of 3-d points in decreasing order of z, you 
could write:

class Point:
    def __init__(self, x,y,z):
        self.x, self.y, self.z = x, y, z
    def __cmp__(self, other):
        return -cmp(self.z, other.z)
        # or: return cmp(other.z, self.z)

Now if you create a list of points (x) and call x.sort(), the points 
will be sorted in decreasing-z order.

Another way to define the sorting criterion is to pass a cmp-like 
function as the argument to x.sort(). To re-sort your points in 
increasing-y order, you can write:

x.sort(lambda self,other: cmp(self.y, other.y))

or if you don't like lambdas:

def y_sorter(u,v):
    return cmp(u.y, v.y)
x.sort(y_sorter)


-------------------------------------------------------------
How do I perform an os.popen() on NT?
http://www.faqts.com/knowledge-base/view.phtml/aid/5396
-------------------------------------------------------------
Gord Broom, Fiona Czuczman
Mark Hammond

For Python versions 1.6 and before, see Python FAQ entry 7.13 -
http://www.python.org/doc/FAQ.html#7.13.  For Python 2.0, os.popen() 
works correctly on Windows.







More information about the Python-list mailing list