Python: Difference between revisions

From LPTMS Wiki
Jump to navigation Jump to search
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== documentation ==
== Documentation ==


* [http://www.python.org Official website]
* [http://www.python.org Official website]
* [http://diveintopython.org Dive into Python]
* [http://www.euroscipy.org euroscipy] (scientific python community)
* [http://www.euroscipy.org euroscipy] (scientific python community)
* [http://scipy-lectures.github.com Getting started with scipy]
* [http://scipy-lectures.github.com Getting started with scipy]
* [http://www.unixgarden.com/index.php/programmation/python-comme-langage-scientifique Python comme langage scientifique] - Voir aussi Cython.
* [http://www.unixgarden.com/index.php/programmation/python-et-le-c Python et le C]


== Libraries ==
== Libraries and softwares ==


* [http://ipython.org iPython]
* [http://ipython.org iPython]
* [http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html the iPython notebook] (interface similar to Mathematica) use HTML to handle worksheets.
* [http://docs.python.org/library Standard Library]
* [http://docs.python.org/library Standard Library]
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]
Line 15: Line 17:
* [http://cython.org Cython]
* [http://cython.org Cython]
* [http://www.pytables.org PyTables]
* [http://www.pytables.org PyTables]
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]
* [http://pypy.org/ PyPy], a just-in-time compiler/implementation of Python.
* [https://pandas.pydata.org/ Pandas, data science]


== Miscellaneous ==
== Miscellaneous ==


* [http://fperez.org/code/index.html Fernando Perez page on Python]
* [http://fperez.org/code/index.html Fernando Perez page on Python]
* [[Interfacing C++ and Python]]
* [[Interfacing C++ and Python]].
* [http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html Interfacing Python and C++] (the other way around). See also Cython, below.
* [[Scientific Programming with Python (for the debug), and C(ython) for the speed]]
* [[Fitting data with python]]
* [[Fitting data with python]]
* [http://code.enthought.com/projects/mayavi/ 3D Scientific Data Visualization and Plotting]
* [[Quick integration of a known function]]
* [[Reading a large data file (efficiently)]]


== Tips ==
== Tips ==
* with '''pylab''', removes the white borders:
<source lang="py">
savefig('figure.eps',format='eps',bbox_inches="tight")
</source>
* equivalent of the C ternary operator ?: (''test'' ? ''restrue'' : 'resfalse''), use a tuple is possible but not transparent
<source lang="py">
(resfalse,restrue)[test]
</source>
prefer the inline condition testing way
<source lang="py">
res = restrue if test or resfalse
# example
min = lambda x,y: x if x<y else y
min(1,2)
</source>


* adding a path to a directory containing your module files
* adding a path to a directory containing your module files
Line 28: Line 55:
import sys
import sys
sys.path += [ "/home/username/bin/Python" ]
sys.path += [ "/home/username/bin/Python" ]
</source>
* test whether a string has only digits or letters
<source lang="py">
str = '1321'
str.isdigit() # returns True/False
str.isalpha() # returns True/False
</source>
* Nested for loops in a single line:
<source lang="py">
for n,m in [ (n,m) for n in range(10) for m in range(2) ]:
    print n,m
</source>
</source>

Latest revision as of 15:16, 9 December 2020

Documentation

Libraries and softwares

Miscellaneous

Tips

  • with pylab, removes the white borders:

<source lang="py"> savefig('figure.eps',format='eps',bbox_inches="tight") </source>

  • equivalent of the C ternary operator ?: (test ? restrue : 'resfalse), use a tuple is possible but not transparent

<source lang="py"> (resfalse,restrue)[test] </source> prefer the inline condition testing way <source lang="py"> res = restrue if test or resfalse

  1. example

min = lambda x,y: x if x<y else y min(1,2) </source>

  • adding a path to a directory containing your module files

<source lang="py"> import sys sys.path += [ "/home/username/bin/Python" ] </source>

  • test whether a string has only digits or letters

<source lang="py"> str = '1321' str.isdigit() # returns True/False str.isalpha() # returns True/False </source>

  • Nested for loops in a single line:

<source lang="py"> for n,m in [ (n,m) for n in range(10) for m in range(2) ]:

   print n,m

</source>