360 likes | 457 Views
Windows Python Tutorial. Title. Center for Coastal and Ocean Mapping NOAA/UNH Joint Hydrographic Center. Kurt Schwehr Jan 2007. Day 2 More python. Loops and tests Plotting And more…. Class website: http://vislab-ccom.unh.edu/~schwehr/Classes. What does perl look like?.
E N D
Windows Python Tutorial Title Center for Coastal and Ocean Mapping NOAA/UNH Joint Hydrographic Center Kurt Schwehr Jan 2007
Day 2More python • Loops and tests • Plotting • And more…
First some review of Day 1 • We covered a lot of ground yesterday • Please ask if you have any questions
Reading files – Step 1 • First create a file to read • Save it as data01.txt on the desktop
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
Make a data file with some numbers • Save as data02.txt
Read as textHow do we skip lines that start with ‘#’? • Use if and continue
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”
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
Make that a function so you can reuse it! • Use SciTE to create ‘ex04.py’
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