[FAQTS] Python Knowledge Base Update -- September 20th, 2000

Fiona Czuczman Fiona Czuczman <fiona@sitegnome.com>
20 Sep 2000 11:14:16 -0000


Back to my nocturnal habits... 

The latest entries into http://python.faqts.com

Fiona


## Unanswered Questions ########################################


-------------------------------------------------------------
How can I use the ConfigParser to parse through a text file?
http://www.faqts.com/knowledge-base/view.phtml/aid/5928
-------------------------------------------------------------
Sumita Ponnuchamy



## New Entries #################################################


-------------------------------------------------------------
Setting Focus in Pmw.Dialog
http://www.faqts.com/knowledge-base/view.phtml/aid/5936
-------------------------------------------------------------
Fiona Czuczman
Matthew Dixon Cowles

Problem:

I use Pmw.Dialog to prompt the user for some text.
The dialog is just what I need, but for some reason I can't set the 
initial keyboard focus to the entry field.

The standard "askstring" dialog doesn't give me control over the edit 
field size (that I can see), so I tried this:

------------------------------------------------------------------------
 dialog = Pmw.Dialog( root,
       buttons = ( 'OK', ),
       buttonboxpos = S,
       title = 'Prompt' )

 w = Pmw.EntryField( dialog.interior(), label_text = prompt, labelpos = 
NW, labelmargin = 1, entry_width = 50 )
 w.pack( padx = 15, pady = 15 )

 dialog.configure( activatecommand = w.focus_set )
 dialog.focus_force()

 dialog.activate()
----------------------------------------------------------------------

The result of "dialog.configure( activatecommand = w.focus_set )" is 
that the dialog doesn't get focus at all.

If I comment this line out, the dialog gets focus, but the user has to 
click in the entry field, or tab twice to get to it (first tab goes to 
OK button).

Solution:

Your problem is that a Pmw.EntryField is itself a compound widget
(I've been caught by this one too). You want something like:

dialog.configure( activatecommand = w.component("entry").focus_set )

You can also get a similar result by replacing

dialog.configure( activatecommand = w.focus_set )
dialog.focus_force()

with

w.component("entry").focus_force()


-------------------------------------------------------------
How do I pass on keyword arguments in a function?
http://www.faqts.com/knowledge-base/view.phtml/aid/5937
-------------------------------------------------------------
Fiona Czuczman
Johann Hibschman, Greg Ewing

Problem:

-------------

def mark( a, b , **kw):
   print 'Mark' 
   passKeywords(kw) # THIS DOESN'T WORK!!! MAKE IT WORK!!!

def passKeywords( a,**kw )
   """ just do something  """
   print 'Gibson'

-------------


call it:

doSomething( 1,3,name='Mark',Last='Gibson')

produces:

Mark
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in mark
TypeError: too many arguments; expected 0, got 1

-----------------
What I want to know is how do I pass kw from mark() to passKeywords()?

Solution:

apply(passKeywords, (), kw)

Or, in Python 2.0,

   passKeywords(**kw)


-------------------------------------------------------------
What is the exact purpose of fileno()?
http://www.faqts.com/knowledge-base/view.phtml/aid/5938
-------------------------------------------------------------
Fiona Czuczman
Donn Cave

The file object is an I/O buffer and a device.  The C library allocates
space for the buffer in your process memory, and when you read or write
the data comes from or goes to that buffer.  The stdio C library 
functions manage the buffer by reading or writing to the device.

Since physical device access is a very expensive operation for the 
computer, buffering like that basically allows you to work with small or 
random size I/O requests while economizing on system resources.  
However, there are times when you need to do something that the stdio 
library doesn't account for, like select(), or a filesystem lock, or 
some terminal driver function.

The fileno() function exposes the file object's file descriptor or unit
number, which on UNIX is the raw device.  Select() already knows about
fileno(), so you can give it a socket or whatever and it will call 
fileno() itself, but usually it's up to you to call fileno() and get the 
descriptor.

Of course the socket fileno() function is more or less the same idea as
the file object's fileno(), but the socket isn't a file object and 
doesn't have its own buffer.  (On UNIX you can make a file object from a 
socket, but it's difficult to make that work both properly and 
efficiently with select().)  The result from socket fileno() is a file 
descriptor on UNIX, but it isn't necessarily so on other operating 
systems.

You can get file descriptors directly if you use the posix.open() 
function, (A.K.A. os.open().)


-------------------------------------------------------------
Is there an easy way given an internal webpage to cycle through all the links on the page and find which ones are broken?
http://www.faqts.com/knowledge-base/view.phtml/aid/5939
-------------------------------------------------------------
Fiona Czuczman
Jeremy Hylton, Dan Gindikin

Look at Tools/webchecker in the Python distribution.

Check out linkchecker.sourceforge.net


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


-------------------------------------------------------------
How do I get the full pathname of a module?  Let's say I use 'import' to load a module.  How can I find the location of its *.py or *.pyc file?
http://www.faqts.com/knowledge-base/view.phtml/aid/5918
-------------------------------------------------------------
Rolf Freimuth, Fiona Czuczman
Mike Fletcher

def modulePath( module ):
        import os
        return os.path.abspath( module.__file__ )