Python: Difference between revisions
Jump to navigation
Jump to search
(→Tips) |
(→Tips) |
||
Line 33: | Line 33: | ||
== Tips == | == Tips == | ||
* equivalent of the C ternary operator ?: (''test'' ? ''restrue'' : 'resfalse''), use a tuple | * equivalent of the C ternary operator ?: (''test'' ? ''restrue'' : 'resfalse''), use a tuple is possible but not transparent | ||
<source lang="py"> | <source lang="py"> | ||
(resfalse,restrue)[test] | (resfalse,restrue)[test] | ||
</source> | </source> | ||
prefer the inline condition testing way | |||
<source lang="py"> | <source lang="py"> | ||
res = restrue if test or resfalse | res = restrue if test or resfalse |
Revision as of 16:24, 16 July 2015
Documentation
- Official website
- euroscipy (scientific python community)
- Getting started with scipy
- Python comme langage scientifique - Voir aussi Cython.
- Python et le C
Libraries and softwares
- iPython
- the iPython notebook (interface similar to Mathematica) use HTML to handle worksheets.
- Standard Library
- SciPy - NumPy
- Matplotlib
- SymPy
- Cython
- PyTables
- Modular toolkit for Data Processing
- PyPy, a just-in-time compiler/implementation of Python.
Miscellaneous
- Fernando Perez page on Python
- Interfacing C++ and Python.
- 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
- 3D Scientific Data Visualization and Plotting
- Quick integration of a known function
- Reading a large data file (efficiently)
Tips
- 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
<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>