Skip to content

Commit

Permalink
Improved Python 3 compatibility.
Browse files Browse the repository at this point in the history
Added Exception type at the urllib import statement.
raw_input() was replaced by input() in Python 3, so NameError exception will be raised in Python 3 and input() would be used instead.
  • Loading branch information
Yohanna committed Sep 12, 2014
1 parent aa7a3a8 commit cc2b2e5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions udemy-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import os
import json
from bs4 import BeautifulSoup

try:
from urllib import urlretrieve
except:
from urllib.request import urlretrieve
from urllib import urlretrieve # Python 2
except ImportError:
from urllib.request import urlretrieve # Python 3


class Session:
Expand Down Expand Up @@ -159,12 +160,16 @@ def main():
link = args['link']

if not username:
print('Username/Email:'),
username = raw_input()
try:
username = raw_input("Username/Email: ") # Python 2
except NameError:
username = input("Username/Email: ") # Python 3

if not password:
password = getpass.getpass(prompt='Password: ')

udemy_dl(username, password, link)


if __name__ == '__main__':
main()

0 comments on commit cc2b2e5

Please sign in to comment.