Difference between revisions of "Python"

From LPTMS Wiki
Jump to: navigation, search
(Tips)
(Libraries and softwares)
 
(One intermediate revision by the same user not shown)
Line 19: Line 19:
 
* [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.
 
* [http://pypy.org/ PyPy], a just-in-time compiler/implementation of Python.
 +
* [https://pandas.pydata.org/ Pandas, data science]
  
 
== Miscellaneous ==
 
== Miscellaneous ==
Line 32: Line 33:
  
 
== 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
 
* equivalent of the C ternary operator ?: (''test'' ? ''restrue'' : 'resfalse''), use a tuple is possible but not transparent

Latest revision as of 15:16, 9 December 2020

Documentation

Libraries and softwares

Miscellaneous

Tips

  • with pylab, removes the white borders:

savefig('figure.eps',format='eps',bbox_inches="tight")
  • equivalent of the C ternary operator ?: (test ? restrue : 'resfalse), use a tuple is possible but not transparent

(resfalse,restrue)[test]

prefer the inline condition testing way

res = restrue if test or resfalse
# example
min = lambda x,y: x if x<y else y
min(1,2)
  • 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