Skip to content

Instantly share code, notes, and snippets.

@dnene
Created January 17, 2012 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnene/1626867 to your computer and use it in GitHub Desktop.
Save dnene/1626867 to your computer and use it in GitHub Desktop.
python is for computer scientists ?
import csv
import StringIO
data = """Bob,Dobbs,bob@dobbs.com,25.00
Rocket J.,Squirrel,rocky@frostbite.com,0.00
Bullwinkle,Moose,bull@frostbite.com,0.25
Vim,Wibner,vim32@goomail.com,25.00"""
data_stream = StringIO.StringIO(data)
dataReader = csv.reader(data_stream)
#dataReader = list(csv.reader(data_stream)) <-- equivalent to toIndexedSeq
print "Printing once"
print "\n".join(map(lambda x: str(x), dataReader))
print "Printing twice"
print "\n".join(map(lambda x: str(x), dataReader))
print "Printing over"
# Actual Output
# Printing once
# ['Bob', 'Dobbs', 'bob@dobbs.com', '25.00']
# ['Rocket J.', 'Squirrel', 'rocky@frostbite.com', '0.00']
# ['Bullwinkle', 'Moose', 'bull@frostbite.com', '0.25']
# ['Vim', 'Wibner', 'vim32@goomail.com', '25.00']
# Printing twice
#
# Printing over
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment