Skip to content

Old Python files

December 11, 2009

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:

 #!/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 Comments leave one →
  1. December 11, 2009 11:40 am

    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 …

    • michellejw permalink*
      December 11, 2009 11:48 am

      hey, thanks! 🙂
      I’m still pretty new to all this, and am sure to do silly things – thanks for catching that one!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: