[FAQTS] Python Knowledge Base Update -- July 14th, 2000

Fiona Czuczman fiona at sitegnome.com
Fri Jul 14 00:14:48 EDT 2000


Hello!

Once again another collection of entries into http://python.faqts.com

Cheers,

Fiona


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


-------------------------------------------------------------
How do I import a file that isn't in the pythonpath?
http://www.faqts.com/knowledge-base/view.phtml/aid/4719
-------------------------------------------------------------
Fiona Czuczman
Mike 'Cat' Perkonigg

The easiest way is to put '.' in your PYTHONPATH.
But you can extend your path with any directory in your python code 
with:

>>>import sys
>>>sys.path.append (path-to-load-modules-from)


-------------------------------------------------------------
Is there a Python module that would allow me to easily parse and format vCards?
http://www.faqts.com/knowledge-base/view.phtml/aid/4720
-------------------------------------------------------------
Fiona Czuczman
Henning Schroeder

The new WorldPilot 1.1alpha contains such a module (file vCard.py)

ftp://demo.worldpilot.com/pub wppocket-1.1.0alpha2.tgz

(see wppocket-1.1.0alpha2.tgz)


-------------------------------------------------------------
Is there anybody who has worked on wbmp converter image from any other format in Python? If yes, where can I find it?
http://www.faqts.com/knowledge-base/view.phtml/aid/4721
-------------------------------------------------------------
Fiona Czuczman
Duncan Booth

Try http://www.rcp.co.uk/distributed/Downloads

The file wbmpconv.zip (1192k) is a command line convertor to/from wbmp 
format (Win32 binary). Alternatively, wbmpconvsrc.zip (8k) contains the 
python sources. The source version requires that you have Python and PIL 
installed on your machine, the binary is completely self contained but a 
bit large as it needs to include the Python and Tk dlls.

Obviously the source version lets you convert to/from any image formats 
supported by PIL, the win32 binary supports:
ARG BMP* CUR DCX EPS* FLI FPX GBR GIF* ICO IM* IMT IPTC JPEG* MCIDAS MIC 
MPEG MSP* PCD PCX* PIXAR PNG* PPM* PSD SGI SUN TGA TIFF* WBMP* WMF XBM* 
XPM XVTHUMB (the ones with a * may be read or written, the other formats 
may only be read).


-------------------------------------------------------------
What is UnboundLocalError for?
http://www.faqts.com/knowledge-base/view.phtml/aid/4722
-------------------------------------------------------------
Fiona Czuczman
Tim Peters

When a local name is referenced but has not been bound to a value.  In 
other words, it's an unbound local error <wink>.  Note that 
UnboundLocalError is a subclass of NameError, because it's a more 
specific form of NameError, so old code expecting to catch NameError 
exceptions will still catch UnboundLocalError exceptions.  In 1.5.2 and 
before, NameError was thrown regardless of whether the offending name 
was local or global.  So UnboundLocalError gives more information.

> I encountered it when I made a mistake like this:
>
> >>> f()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "<stdin>", line 1, in f
> UnboundLocalError: l
> >>>

So your function f (which you have not shown us) refers to a local name 
"l" which you didn't give a value before referencing it.  It's 
impossible for us to guess what you put in the body of f; here's one 
possibility:

>>> def f():
...     l = l + 1   # local "l" referenced on the right before 
definition
...     return l
...
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in f
UnboundLocalError: l
>>>


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


-------------------------------------------------------------
What is wxPython? How does it compare with Tkinter?
http://www.faqts.com/knowledge-base/view.phtml/aid/3565
-------------------------------------------------------------
Fiona Czuczman, Olivier Dagenais
Shae Erisson,http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin465.htm#wxpother

wxPython [ http://www.wxpython.org ] is a set of Python bindings for 
the GUI toolkit wxWindows [ http://www.wxwindows.org ], that was 
written as a C++ library to provide a platform-independant way of 
implementing rich and fast user interfaces.

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

I chose wxPython over Tkinter (for my projects) because:
- wxWindows seems to have more widgets than Tk
- special widgets (like the TreeView) are implemented using the 
operating system's native implementations, not complete re-writes
- it's more than a "lowest common denominator" among platforms, 
wxWindows seeks to provide the same, advanced functionality on all 
platforms, even if it means they have to write a lot of code to 
complement a platform's native component
- wxWindows seems to cover more ground, in terms of functionality (it's 
more than a GUI toolkit, it also seeks to provide functions/classes for 
files, threads, printing, clipboard, networking, ODBC, etc...)
- I was *really* impressed with the wxPython demo

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

The wxWindows documentation emphasizes the "less good" points of other 
GUI toolkits (namely Tkinter) to motivate wxPython:

http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin465.htm#wxpothe
r


-------------------------------------------------------------
Should __getattr__ increment the reference count before it returns the appropriate attribute, or not? writing a Python module in C
http://www.faqts.com/knowledge-base/view.phtml/aid/2907
-------------------------------------------------------------
Fiona Czuczman
Gordon McMillan

It should incref the attribute and leave the owner alone.

Imagine a sequence like this:
 newref = a.b # here's your __getattr__
 a = None
Now a's refcount drops. If it drops to 0, it gets deallocated, which 
will decref b. Without an incref in __getattr__, the user would have 
an invalid reference.


-------------------------------------------------------------
How do I check to see if a file exists?
http://www.faqts.com/knowledge-base/view.phtml/aid/2782
-------------------------------------------------------------
Fiona Czuczman
Fredrik Lundh,Peter Schneider-Kamp

To check if a file exists use:

>>> import os.path
>>> os.path.exists("python/")
1
>>> os.path.exists("spam/")
0
>>> os.path.exists("python/patches/submitted/array.pop-extend.patch")
1

If you only want a true for regular files have a look at isfile():

>>> os.path.isfile("python/")
0
>>> os.path.isfile("spam/")
0
>>> os.path.isfile("python/patches/submitted/array.pop-extend.patch")

for more info or other function look at:
http://python.org/doc/current/lib/module-os.path.html







More information about the Python-list mailing list