Skip to content

Commit 431f38a

Browse files
committed
Merge pull request #25 from cameronmarlow/python3-compat
Python3 compatibility in __main__
2 parents 3004eb8 + 9c0de6e commit 431f38a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

microdata.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,13 @@ def _make_item(e):
226226

227227

228228
if __name__ == "__main__":
229-
import urllib
229+
try:
230+
from urllib.request import urlopen
231+
except ImportError:
232+
from urllib import urlopen
233+
230234
if len(sys.argv) < 2:
231-
print "Usage: %s URL [...]" % sys.argv[0]
235+
print("Usage: %s URL [...]" % sys.argv[0])
232236
sys.exit(1)
233237

234238
for url in sys.argv[1:]:
@@ -237,7 +241,7 @@ def _make_item(e):
237241
microdata = {}
238242
microdata['items'] = items = []
239243

240-
for item in get_items(urllib.urlopen(url)):
244+
for item in get_items(urlopen(url)):
241245
items.append(item.json_dict())
242246

243-
print json.dumps(microdata, indent=2)
247+
print(json.dumps(microdata, indent=2))

0 commit comments

Comments
 (0)