Size: 1630
Comment:
|
Size: 1337
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 25: | Line 25: |
= Standard modules = * System, e.g. {{{sys.argv}}} * OS, e.g. {{{os.system()}}} * File globbing, e.g. {{{glob.glob('*.txt')}}} * |
|
Line 28: | Line 34: |
* Plotting, e.g. {{{plot()}}}, {{{contour}}} Example: {{density.png}} {{{#!python from pylab import * # The seawater module is installed only for Python2.6.2 # module load Python/2.6.2 import seawater S=linspace(0,35) T=linspace(-2,35.0) rho=zeros((S.size,T.size)) for i,t in enumerate(T): rho[i,:]=seawater.dens(S,t) figure() CS = contour(S,T,rho,15,colors='k') clabel(CS, fontsize=8, inline=1) ylabel('Temperature [$^\circ$C]') xlabel('Salinity') title('Sea water density [kg/m$^3$]') show() savefig('density.png',dpi=75) }}} |
* Plotting, e.g. {{{plot()}}}, {{{contour()}}} * Netcdf, e.g. {{{fid=scipy.io.netcdf_file(filename,'r')}}}, {{{fid.variables}}} |
Basic Python
- Allowed names for identifier
Assignments, e.g. a=1, a,b=1,2, a+=1
Comparisons, e.g. ==, !=
Lists and their methods, e.g. L.append()
Strings and their methods, e.g. .replace(), .split(),
Dictionaries and their methods, e.g. D.keys()
Indexing and slicing, e.g. L[-2:]
Loops, e.g. for i,j in enumerate(['Hund','Katze','Maus']):
Control statements, e.g. if
Importing modules, e.g. import scipy
Getting help, e.g. help()
Defining functions, e.g. def function(x,y):
Working with files, e.g. fid=open(filename,'r')
Standard modules
System, e.g. sys.argv
OS, e.g. os.system()
File globbing, e.g. glob.glob('*.txt')
scipy, numpy, pylab
Array creation, e.g. zeros(), array(), linspace()
Array methods, e.g. .shape(), .reshape(), .tofile(), .flat(), .transpose()
Plotting, e.g. plot(), contour()
Netcdf, e.g. fid=scipy.io.netcdf_file(filename,'r'), fid.variables