Download presentation
Presentation is loading. Please wait.
1
Title Center for Coastal and Ocean Mapping NOAA/UNH Joint Hydrographic Center Windows Python Tutorial Kurt Schwehr Jan 2007
2
Day 2 More python Loops and tests Plotting And more…
3
Class website: http://vislab-ccom.unh.edu/~schwehr/Classes
4
What does perl look like?
5
First some review of Day 1 We covered a lot of ground yesterday Please ask if you have any questions
6
Lists are created with [ ]
7
Use tab to find out what ‘methods’ are available
8
Getting help on functions
9
Asking a function or module for help
10
Start ipython
11
If tests and indentation matters
12
for loops
13
Matplot lib
14
1st plot
15
2nd plot
16
Discreet samples form a sine wave
17
Reading files – Step 1 First create a file to read Save it as data01.txt on the desktop
18
Get to the Desktop in IPython
19
Now read the file Finish the for loop by going by unindenting Each line is getting to new line characters Use a comma to prevent the double end line
20
Make a data file with some numbers Save as data02.txt
21
Read as text How do we skip lines that start with ‘#’? Use if and continue
22
Now we need to get these values to be numbers The variable line still has the last line read How can we get the float values of “3 2.2”
23
Now put it all together in a script Use SciTE to create the file SciTE does not know this is python until you save the file
24
Run the script
25
Make that a function so you can reuse it! Use SciTE to create ‘ex04.py’
26
Those ‘-’ in the left column collapse code
27
Import ex04
28
Use ex04.read_y to get some data
29
Plot it!
30
Save the plot
31
Write some data to disk Use file to open a file, but tell it ‘w’ to open for writing write does not append a newline and only takes strings Close the file to make sure the data is written into the file
32
View the data in SciTE
33
Time is important for data logging
34
Adding documentation to modules and functions
36
The ex05 module now has a help
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.