Old Python files

I was just browsing through an old external hard drive and came across some python scripts that I wrote as part of a Python tutorial that I did back in grad school.  It’s funny – “hello world” and all that…

Here’s one for reading an ascii text file:

[sourcecode language=”python”]
#!/usr/bin/env python

# Read in data while skipping comment lines

for line in file(‘data02.txt’):
if line[0]==’#’:
continue # Skip comment lines in the file
x,y = line.split()
x,y = float(x),float(y)
print ‘x =’,x,’and is of type’,type(x)
print ‘y =’,y,’and is of type’,type(y)

The file “data02.txt” contains the following text:

# This is a comment line
0 1
1 2
2 1.5
3 2.2

2 thoughts on “Old Python files

  1. Head’s up – there are leftover <code> tags in your code block (including a closing tag [ with </] first, then the opening tag after).

    I hope WP’s comments will take my escaped brackets …

Leave a Reply to Philip Kahn Cancel reply

Your email address will not be published. Required fields are marked *