IDLE (Python 3.8 32-bit)
===============
Запускаю скрипт:
# -*- coding: utf-8 -*- #!/usr/bin/env python3 import sys import urllib import urllib.request import urllib.error import os from urllib.parse import urlparse def get_url_nofollow(url, pathTo): try: urllib.request.urlretrieve (url, pathTo) return 1 except urllib.error.HTTPError as e: return 0 except: return 0 def main(args): urls = [] # urls = {} arguments = len(args) - 1 filepath1 = 'printer1.mu3' filepath2 = 'err.mu3' if arguments > 1: filepath1 = args[1] if arguments >= 2: chan = args[2] if arguments >= 3: filepath2 = args[3] plist = "plist.m3u" plistF = open(plist, "w", encoding = "utf-8") with open(filepath1, encoding = "utf-8") as fp: line = fp.readline() cnt = 1 while line: line = line.strip() line = line.strip('\n') line = line.strip('\r') a = urlparse(line) pathTo = filepath2 + '\%s' % os.path.basename(a.path) out = get_url_nofollow(line, pathTo) if (out != 1): print("not found - " + line) else: urls.append(pathTo) line = fp.readline() fp.close() with open(chan, encoding = "utf-8") as fc: chName = fc.readline() while chName: chName = chName.strip() chName = chName.strip('\n') chName = chName.strip('\r') print(chName) for url in urls: # print(url) with open(url, encoding = "utf-8") as fo: line = fo.readline() # print(line) cnt = 1 while line: if (line.find(chName) != -1): plistF.write(line) line = fo.readline() plistF.write(line) line = fo.readline() fo.close() chName = fc.readline() fc.close() plistF.close() if __name__ == "__main__": main(sys.argv[0:])
>>>
Warning (from warnings module):
File “C:\Users\Александр\Desktop\printer1mu3\download_m3u.py”, line 45
pathTo = filepath2 + ‘\%s’ % os.path.basename(a.path)
SyntaxWarning: invalid escape sequence \%
>>>
====== RESTART: C:\Users\Александр\Desktop\printer1mu3\download_m3u.py ======
Traceback (most recent call last):
File “C:\Users\Александр\Desktop\printer1mu3\download_m3u.py”, line 87, in <module>
main(sys.argv)
File “C:\Users\Александр\Desktop\printer1mu3\download_m3u.py”, line 37, in main
with open(filepath1, encoding = “utf-8”) as fp:
FileNotFoundError: No such file or directory: ‘printer1.mu3’
>>>
Как исправить ?