использовать argparse
one_line = f'--file="someshit.compressed.mp4" --title="{title}" --description="{description}" --category="{category}" --keywords="{keywords}"'
import json, argparse from shlex import split parser = argparse.ArgumentParser() parser.add_argument('--file', required=True, help='Video file to upload') parser.add_argument('--title', help='Video title', default='Test Title') parser.add_argument('--description', help='Video description', default='Test Description') parser.add_argument('--category', default='22', help='Numeric video category.') parser.add_argument('--keywords', help='Video keywords, comma separated', default='') parser.add_argument('--privacyStatus', default='public', help='Video privacy status.') with open("yt_vid_info.json", "r") as fff: data = json.loads(fff.read()) title = data['video_title'] description = data['video_description'] keywords = data['video_keywords'] category = data['video_category'] one_line = f'--file="someshit.compressed.mp4" --title="{title}" --description="{description}" --category="{category}" --keywords="{keywords}"' command = split(one_line) for cmd_cmd in command: # print(cmd_cmd) args = parser.parse_args(cmd_cmd) print(args) у меня выходит эта ошибка usage: run_cmd.py [-h] --file FILE [--title TITLE] [--description DESCRIPTION] [--category CATEGORY] [--keywords KEYWORDS] [--privacyStatus PRIVACYSTATUS] run_cmd.py: error: the following arguments are required: --file
А зачем эта возня вообще?
Обсуждают сегодня