Difference between revisions of "Python"
From Tmplab
(→Intro) |
|||
Line 7: | Line 7: | ||
= Tricks = | = Tricks = | ||
+ | |||
+ | == content of objects == | ||
+ | |||
Finding what's in an object | Finding what's in an object | ||
>>> dir(obj) | >>> dir(obj) | ||
+ | |||
+ | = Debugging = | ||
+ | |||
+ | See http://pythonconquerstheuniverse.wordpress.com/category/the-python-debugger/ | ||
+ | |||
+ | import pdb | ||
+ | pdb.set_trace() | ||
+ | |||
= Editor tricks = | = Editor tricks = |
Revision as of 22:54, 22 October 2009
Contents
Intro
This cheat sheet helps troubleshoot common problems...
Some good documentation source:
- http://www.python.org/doc/2.5.4/download/
- apprendre a programmer avec python by gerard swinnen (french, free PDF on the net)
Tricks
content of objects
Finding what's in an object
>>> dir(obj)
Debugging
See http://pythonconquerstheuniverse.wordpress.com/category/the-python-debugger/
import pdb pdb.set_trace()
Editor tricks
Emacs
See http://python.about.com/b/2007/09/24/emacs-tips-for-python-programmers.htm
- C-c <: Shift the region to the left
- C-c >: Shift the region to the right
Problems
I installed some modules / packages and can't load them
echo $PYTHONPATH
$ python Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys for i in sys.path: print i
You can add a .pth file in one of the already loaded dir: see http://djangotricks.blogspot.com/2008/09/note-on-python-paths.html
like:
# cat > /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/others.pth /Library/Python/2.5/site-packages/ ^D