Difference between revisions of "Python"

From LPTMS Wiki
Jump to: navigation, search
m (Miscellaneous)
m (Libraries and softwares)
Line 18: Line 18:
 
* [http://www.pytables.org PyTables]
 
* [http://www.pytables.org PyTables]
 
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]
 
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]
 +
* [http://pypy.org/ PyPy], a just-in-time compiler/implementation of Python.
  
 
== Miscellaneous ==
 
== Miscellaneous ==

Revision as of 16:00, 15 November 2013

Documentation

Libraries and softwares

Miscellaneous

Tips

  • equivalent of the C ternary operator ?: (bool ? restrue : 'resfalse), use a tuple

(resfalse,restrue)[bool]
  • adding a path to a directory containing your module files

import sys
sys.path += [ "/home/username/bin/Python" ]
  • test whether a string has only digits or letters

str = '1321'
str.isdigit() # returns True/False
str.isalpha() # returns True/False
  • Nested for loops in a single line:

for n,m in [ (n,m) for n in range(10) for m in range(2) ]:
    print n,m