I wanted to download files from the web and name them, plus i wanted to make a thread so i will download different files at the same time.
import urllib.request
import threading
class mythread(threading.Thread):
def __init__(self, threadID, Name, URL):
threading.Thread.__init__(self)
self.threadID = threadID
self.Name = Name
self.URL = URL
def run(self):
print("Starting :" + self.Name + " \n ")
download_data(self.URL, 1, self.Name)
print("Exiting :" + self.Name + " \n ")
def download_data(URL, delay, Name):
URL = " "
response = urllib.request.urlopen(URL)
data = response.read()
text = data.decode('utf-8')
while text:
time.sleep(delay)
if text is None:
break
print(text)
thread1 = mythread(1, romeo, https: // www.py4e.com/code3/romeo-full.txt)
thread2 = mythread(2, romeo2, https: // www.py4e.com/code3/romeo.txt)
thread1.start()
thread2.start()
thread1.join()
thread2.join()