using with for filehandles

nopraw
David Trail 13 years ago
parent cad8605fe5
commit 0d2fcdf0c5

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

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

Loading…
Cancel
Save