using with for filehandles

nopraw
David Trail 13 years ago
parent cad8605fe5
commit 0d2fcdf0c5

@ -1,14 +1,14 @@
#!/usr/bin/env python2
from __future__ import with_statement
import sys
try: import json
except ImportError: import simplejson as json
from urllib2 import urlopen, HTTPError
from time import sleep
f = open('user.json', 'r')
user = json.load(f)['user']
f.close()
with open('user.json', 'r') as f:
user = json.load(f)['user']
sub_section = 'comments'
after = ''

@ -8,9 +8,8 @@ from datetime import datetime, timedelta
from time import sleep
## Get the data we need to log into the API
f = open('user.json', 'r')
data = json.load(f)
f.close()
with open('user.json', 'r') as f:
data = json.load(f)
days = data['days']
user = data['user']

Loading…
Cancel
Save