Skip to content

Instantly share code, notes, and snippets.

@micktwomey
Created October 2, 2010 14:10
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 micktwomey/607669 to your computer and use it in GitHub Desktop.
Save micktwomey/607669 to your computer and use it in GitHub Desktop.
python basics
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
scheme number
scheme1 5.23456
scheme2 563.7655
scheme3 34534.734534
scheme4 34534.76546756
data = {
"answer": 10,
"answer2": 20,
}
data["answer3"] = data["answer"] * data["answer2"]
html = """<htm>
<head><title>...</title></head>
<body>
<p>The answer = %(answer)d and %(answer2)d</p>
<p>calculated %(answer3)d</p>
</body>
</htm>"""
print html % data
import csv
fp = open("/Users/mick/Desktop/data.txt")
for row in csv.DictReader(fp, delimiter="\t"):
print row
# {'scheme': 'scheme1', 'number': '5.23456'}
# {'scheme': 'scheme2', 'number': '563.7655'}
# {'scheme': 'scheme3', 'number': '34534.734534'}
# {'scheme': 'scheme4', 'number': '34534.76546756'}
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
data = {
"answer": 10,
"answer2": 20,
}
data["answer3"] = data["answer"] * data["answer2"]
html = """<htm>
<head><title>...</title></head>
<body>
<p>The answer = %(answer)d and %(answer2)d</p>
<p>calculated %(answer3)d</p>
</body>
</htm>"""
return html % data
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment