[FAQTS] Python Knowledge Base Update -- May 24th, 2000

Fiona Czuczman fiona at sitegnome.com
Wed May 24 10:09:46 EDT 2000


Hi Guys!

I've entered another lot of questions into http://python.faqts.com

Thanks,

Fiona Czuczman


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


-------------------------------------------------------------
How can I set-up the variable $PYTHONHOME?
http://www.faqts.com/knowledge-base/view.phtml/aid/3206
-------------------------------------------------------------
Fiona Czuczman
Frank Mattes

This is typically done in your shell resource file, in your home dir.
If you happen to have Beazley's Essential Reference (which is a good
idea), see pg 84.

For csh or tcsh, edit ".cshrc":
setenv PYTHONHOME /opt/python

For bash edit ".bashrc"; for ksh edit ".kshrc":
export PYTHONHOME=/opt/python


In both cases, PYTHONHOME can point to the general python home (as 
above) or to both the general home and the exec home, by doing a path
concatenation, e.g.:

export PYTHONHOME=/opt/python:/usr/local/my_special_python

You will have to "source" the "rc" file before it will take effect -- 
the easiest way may be to just log out and log back in.


-------------------------------------------------------------
Is there any way to set a time-out interval when reading URLs?
http://www.faqts.com/knowledge-base/view.phtml/aid/3209
-------------------------------------------------------------
Fiona Czuczman
Oleg Broytmann

Possible ways: use multiprocessing (forking or multithreading); use
non-blocking sockets and select(); use asyncore library.


-------------------------------------------------------------
How do I append to a file instead of overwriting it?
http://www.faqts.com/knowledge-base/view.phtml/aid/3213
-------------------------------------------------------------
Fiona Czuczman
Emile van Sebille, Thomas Wouters

Opening in 'append' mode, by passing 'a' as the 'how' flag to open:

file = open("my_file", "a")

Here's how you can find out:
>>> print open.__doc__
open(filename[, mode[, buffering]]) -> file object

Open a file.  The mode can be 'r', 'w' or 'a' for reading (default),
writing or appending.  The file will be created if it doesn't exist
when opened for writing or appending; it will be truncated when
opened for writing.  Add a 'b' to the mode for binary files.
Add a '+' to the mode to allow simultaneous reading and writing.
If the buffering argument is given, 0 means unbuffered, 1 means line
buffered, and larger numbers specify the buffer size.

Or you can use the Library reference for open(), at 
http://www.python.org/doc/lib/


-------------------------------------------------------------
Where can I find samples for creating and modifying Images with Tkinter?
http://www.faqts.com/knowledge-base/view.phtml/aid/3207
-------------------------------------------------------------
Fiona Czuczman
Fredrik Lundh

Tkinter's PhotoImage class:
http://www.pythonware.com/library/tkinter/introduction/photoimage.htm

the Python Imaging Library comes with Tkinter support (and samples):
http://www.pythonware.com/products/pil/index.htm (info)
http://www.pythonware.com/library/pil/handbook/index.htm (docs)
http://www.pythonware.com/library/pil/handbook/imagetk.htm

also see the scientific computing howto:
http://www.python.org/topics/scicomp/

and the graphics section at the vaults of parnassus:
http://www.vex.net/parnassus/


-------------------------------------------------------------
How can I embed Python into C++ and ship my application to a user not having Python?
Is there a similar mechanism like freeze for embedded Python?
http://www.faqts.com/knowledge-base/view.phtml/aid/3205
-------------------------------------------------------------
Fiona Czuczman
Gordon McMillan, Brent Fulgham

When you embed Python in a program (C or C++), you are linking the
static library that contains the entire Python runtime.  You will
be missing the various "*.py" modules needed for runtime, so these
may need to be included in your distribution.

Freeze your Python. Now take some scissors and cut and paste code 
from frozenmain.c into your embedding app.


-------------------------------------------------------------
How can I save a GIF file in JPEG format?
http://www.faqts.com/knowledge-base/view.phtml/aid/3208
-------------------------------------------------------------
Fiona Czuczman
Greg Landrum

Use the convert method of the Image:

>>> from PIL import Image 
>>> Image.open('prev.gif').convert('RGB').save('prev.jpg')


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


-------------------------------------------------------------
I'm new to Python, where should I start?
Can you give me an overview of the Python Documentation?
Do I need books to learn Python?
http://www.faqts.com/knowledge-base/view.phtml/aid/1356
-------------------------------------------------------------
Nathan Wallace, Fiona Czuczman
Tom Funk,Simon Brunning

The handbook is part of the on-line documentation available at the
Python web site and with the Python installation -- and it's free.

You may not need to go to a bookstore if you peruse the following page:

  http://www.python.org/doc/

The tutorial is quite complete:

  http://www.python.org/doc/current/tut/tut.html

If you work through the tutorial, it should carry you pretty far along
in your quest.  I found it to be *quite* useful.

The Library Reference discusses the modules that ship with Python. 

  http://www.python.org/doc/current/lib/lib.html

The Language Reference is a bit more abstract, and *much* more dry.  
However, it does completely describe the core Python language
constructs, grammar and syntax.   It's often referred to as material for
"Language Lawyers."

  http://www.python.org/doc/current/ref/ref.html

I like the Module Index:

  http://www.python.org/doc/current/modindex.html

It allows you to jump straight to the module of your choice.

If you're using Win32 (as I do), then you may find the MS HTML Help 
version to be useful (it's my favorite).  If you use Win32, you might 
want to check out:

  http://www.orgmf.com.ar/condor/pytstuff.html

Best of all, these very complete works of non-fiction are FREE.... gotta 
love that!  

I own five Python books, but I still find myself referring back to the 
Python documentation regularly.

---

As one newbie to another, I can recommend
<http://www.idi.ntnu.no/~mlh/python/programming.html> for an
introduction to programming, and
<http://www.idi.ntnu.no/~mlh/python/instant.html> for a bit more on
Python. After that, you might want to look at
<http://starship.python.net/crew/amk/grimoire/html/> for a
'cookbook' of useful techniques. If none of these take your fancy,
there are other links at the python site -
<http://www.python.org/doc/Intros.html>.

If you have any questions look ate the FAQs -
<http://www.python.org/doc/FAQ.html>







More information about the Python-list mailing list