[Tutor] Tutor FAQ

Mike Hansen mahansen at adelphia.net
Thu Apr 27 03:19:17 CEST 2006


Here's the next batch of questions and answers for the tutor FAQ. If  
you have any clarifications or corrections, please let me know. I'll  
try to post this on the web site in a couple of days.

---------------------------------------------------------------------
How do I get data out of HTML?

Try Beautiful Soup.
http://www.crummy.com/software/BeautifulSoup/

Beautiful Soup is more forgiving than other parsers in that it won't  
choke on bad markup.

---------------------------------------------------------------------
What's the best editor/IDE for Python?

It's really a matter of preference. There are many features of an  
editor or IDE such as syntax highlighting, code completion, code  
folding, buffers, tabs,  ... Each editor or IDE has some or all of  
these features, and you'll have to decide which features are important  
to you.
See http://wiki.python.org/moin/PythonEditors for a list of editors.
Also http://wiki.python.org/moin/IntegratedDevelopmentEnvironments has  
a list of IDEs.

---------------------------------------------------------------------
How do I make public and private attributes and methods in my classes?

Python followws the philosophy of "we're all adults here" with respect  
to hiding attributes and methods. i.e. trust the other programmers who  
will use your classes. You can't really hide variables and methods in  
Python. You can give clues to other programmers. Python does do name  
mangling. By putting two underscores before the attribute or method  
name and not putting two underscores after the name, Python will mangle  
the name by putting the class name in front of it.

For an short example see
http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_Python

---------------------------------------------------------------------
Why doesn't my regular expression work?

Typically, it's an isssue between re.match and re.search. Match matches  
the beginning only and search checks the entire string. See the regular  
expression HOWTO for more details.

http://www.amk.ca/python/howto/regex/

---------------------------------------------------------------------
How do I perform matrix operations using Python?

The Python FAQ has an entry on how to create multidimensional lists:
http://python.org/doc/faq/programming.html#how-do-i-create-a- 
multidimensional-list

You may want to look into the 'numarray' third party module:
http://www.stsci.edu/resources/software_hardware/numarray

---------------------------------------------------------------------
How do I make an executable out of my Python program?

Although it isn't necessary to turn your Python programs into  
executables, many people want to be able to put their Python programs  
on other machines that don't have Python installed.

Py2exe makes an executable of your Python program. For Windows only.
http://sourceforge.net/projects/py2exe/



More information about the Tutor mailing list