Python is great! I’ve being using python for a while (4 years) and it seems to me the most versatile and lightweight programming language one want to use in a scientific environment.
- General programming: Python supports almost any kind of programming style. Procedural, imperative, object oriented. Plus it it based on advanced objects like arrays, dictionaries, easy string formatting, complex numbers… If you can program it in any language, you can do it easier in Python.
- Very intuitive workflow: in the lab, code changes very quickly. Sometime you need to change a variable, sometime you hack for making an experiment work. Since Python is interpreted, changes are as fast as typing new code.
Scripts can be executed as quickly as double clicking them.
Having a huge standard library makes so that dependency are minimal, and you can move/copy/remove scripts as you like.
Once you have some stable code, you can call/import it from other scripts as it was a library. - Works everywhere: on PC, linux or Mac, with minimal overhead for the system. (Try to install labview or matlab on old pc..). Plus, is free (as in beer and speech)
- Controlling instrument (with and without GUI): You can use any ‘com’ port, or using the Visa drivers for additional options, i.e. GPIB port. In addition, you can directly use C/C++ libraries, as python functions, thanks to ctypes. I’ve being controlling low-level c-routines and high level National Instruments libraries (DAQmx.dll)
- Data analysis: python with numpy rivals matlab for matrices manipulations. You have a similar syntax and matlab scripts can be converted quite easily in python (sometime as easy as removing the ‘;’, reformatting the loops, and checking the indexes). Scipy provides some indispensable discrete math tools such as integrators, differential equations solvers, DFFT and optimizers. With matplotlib you can plot quite easily and generate latex-quality labels.
- The science world is turning Python-esque: more and more science departments are offering Python programming courses (Cornell PhysicsComputationalMethods), and companies are offering Python libraries and support.
Essential packages
Transition to Python3 is still slowly ongoing, so it’s safe and optimal working with Python 2.7. Python3 is not strictly ‘better’, but is an evolution of the language that breaks back-compatibility. Eventually everything will be converted (numpy now has a p3 version).
- Numpy
- Scipy
- matplotlib
- pyVisa (or, more limited, pyserial)
- ctypes (for using non-python api)
You can find everything (but not with the latest updated version) with
IDE
- Notepad++ (Versatile and lightweight text editor)
- Spyder (IDE that comprise texteditor + ipython console + variable explorer, similar to matlab setup)
- Ipython (Powerful python console line, created for numpy/scipy/matplotlib. Version 0.12 has a notebook mode, that behaves similarly to Mathematica interactive notebooks)
Snippets and tutorial
helloworld
[python]
import antigravity
# This is my hello comment
print ‘helloworld’
[/python]
Some more possiblities
[python]
# This is a simple function. z is a default value
def foo(x,y,z = 2):
"""You can also comment here
Indentation set the scope"""
return x+y**z # ** means ‘raise to the power’
x = 4
m = foo(x,3)
results = [] # This is an empty list
for i in xrange(20):
results.append( foo(x,i) )
# You can iterate through a list (or any other ‘iterable’)
for r in results:
print "value = %10.4f "%r # fprint syntax is used
[/python]
Array manipulation
[python]
## Import numpy library
from numpy import *
# create an array from a list of number
x = array([1,222,3.4,4])
# and one from array routines
y = linspace(200,300,4)
print x+y
print x*y # All the operations are element wise
print dot(x,y) # for matrix multiplication
# slice operations are indeed possible
x[:3] = y[1:] # numpy counts from 0 to N-1
[/python]
valtrex wind – valtrex sit valacyclovir pills problem
claritin pills brother – claritin pills treasure loratadine cure
dapoxetine merry – priligy sensible dapoxetine telephone
loratadine medication eye – claritin pills research loratadine medication cloak
ascorbic acid main – ascorbic acid swim ascorbic acid intelligence
promethazine opportunity – promethazine thin promethazine ladder
clarithromycin pills union – cytotec die cytotec passionate
florinef joe – fludrocortisone pills motive prevacid pills boat
rabeprazole 20mg price – order domperidone sale order motilium generic
order dulcolax 5mg online cheap – buy imodium 2mg online cheap liv52 cost
bactrim buy online – levetiracetam 500mg over the counter order tobrex 10mg sale
eukroma cheap – order dydrogesterone 10mg how to buy duphaston
order forxiga 10mg without prescription – doxepin generic buy precose 25mg generic
griseofulvin pill – lopid cost buy generic lopid 300mg
order dimenhydrinate 50mg for sale – prasugrel pills risedronate 35mg drug
buy vasotec generic – order generic doxazosin 2mg buy xalatan generic
etodolac drug – buy cilostazol 100 mg sale pletal ca
piroxicam 20mg sale – rivastigmine 6mg us rivastigmine order online
nootropil 800mg cheap – sinemet pills order sinemet 10mg online cheap
hydrea brand – buy generic ethionamide for sale buy generic robaxin
buy divalproex generic – topiramate 100mg pills where can i buy topamax
purchase disopyramide phosphate – cheap generic norpace buy chlorpromazine 50 mg without prescription
buy cytoxan sale – buy meclizine vastarel without prescription
spironolactone 25mg us – prothiaden price order generic naltrexone 50 mg
buy flexeril medication – cheap aricept online cost enalapril
brand ondansetron – buy selegiline pill order requip 2mg pill
ascorbic acid online – buy isordil buy compro sale
durex gel online purchase – buy durex condoms online cheap buy generic zovirax
rogaine without prescription – buy propecia 5mg pill buy propecia generic
purchase arava generic – order alfacalcidol pills order cartidin online cheap
order atenolol pills – buy carvedilol generic buy carvedilol online cheap
calan pill – order calan 120mg generic buy tenoretic generic
atorlip cost – buy enalapril generic nebivolol 20mg sale
buy lasuna pills for sale – cheap diarex generic buy himcolin
order gasex pill – order diabecon without prescription purchase diabecon pill
order generic trileptal 300mg – how to buy oxcarbazepine purchase levothyroxine sale
purchase imusporin online cheap – purchase colcrys without prescription buy gloperba no prescription
duphalac usa – order lactulose without prescription generic betahistine 16 mg
?????? ?????? ???????? ???????? ??? ??????????? ??????
????????? ?? ?????? ?? ?????? ????????? ????????????? ???????? ?????????? ??????. ???? ????????? ‘GIFT200’ ??? ??????????? ??? ???????? ?????????? ???????, ??????? ????? ???????????? ??? ?????? ??? ????? ?????? ??????????? ???????. ??? ?????????? ?????? ?????? ???? ?? ????????? ????? ?????????? ? ???? ???? ?? ??????? ??? ??????.
cheap calcort – order calcort sale buy generic alphagan online
buy besivance medication – besifloxacin order cost sildamax
gabapentin canada – buy generic gabapentin over the counter sulfasalazine 500 mg usa
order generic colospa – colospa 135mg sale pletal over the counter
buy celecoxib pills for sale – cheap indocin 50mg buy indocin 75mg pills
buy voltaren 100mg generic – purchase aspirin online cheap buy aspirin medication
purchase rumalaya for sale – cheap shallaki buy cheap generic endep
buy cheap voveran – how to get nimodipine without a prescription purchase nimotop without prescription
order baclofen online cheap – buy lioresal piroxicam 20 mg over the counter
buy meloxicam for sale – order toradol without prescription ketorolac where to buy
order cyproheptadine 4 mg sale – tizanidine price buy tizanidine pill