@AiArtsGalleryAnime · Post #6227 · 28.04.2026 г., 06:17
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
TGINSIGHT SIMILAR POSTS
Изворен канал @pythonotes · Post #191 · 14 дек.
Как разделить строку с shell-командой на отдельные аргументы в виде списка? Если сделать просто сплит по пробелу то получим то что надо, кроме случаев со вставками текста с пробелами. Например так: >>> '-arg "I Am Groot"'.split(' ') ['-arg', '"I', 'Am', 'Groot"'] Чтобы учитывать текст в кавычках как единый аргумент можно воспользоваться функцией shlex.split() Кто читает мой канал давно, уже в курсе. А что делать, если нужно обратное действие? Объединить аргументы из списка в строку и при этом добавить кавычки в аргумент с пробелами. Конечно, если вы используете subprocess то он сам всё разрулит. Но если вам нужна именно команда одной строкой, то можно воспользоваться готовой функцией в том же subprocess. >>> from subprocess import list2cmdline >>> list2cmdline(['-arg', 'I Am Groot']) '-arg "I Am Groot"' Он также позаботится об экранировании уже имеющихся кавычек >>> list2cmdline(['-arg', 'I Am "Groot"']) '-arg "I Am \"Groot\""' А вот так он может "схлопнуть" в команду JSON >>> list2cmdline(['--json', json.dumps({'key': 'value'})]) '--json "{\"key\": \"value\"}"' _______________ Возможно кто-то спросит, а зачем соединять аргументы в строку если subprocess сам это сделает а os.system не наш путь? Мне как-то потребовалось отправлять команду на удалённое выполнение и в API поддерживалось указание команды только строкой. Так что всякое бывает) #libs#basic
Пребарај: #serene
@AiArtsGalleryAnime · Post #6227 · 28.04.2026 г., 06:17
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #6203 · 22.04.2026 г., 06:16
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #6179 · 16.04.2026 г., 06:12
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #6155 · 10.04.2026 г., 06:24
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #6128 · 04.04.2026 г., 06:21
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #6104 · 29.03.2026 г., 06:17
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #6068 · 20.03.2026 г., 06:11
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #6042 · 14.03.2026 г., 06:09
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #6017 · 08.03.2026 г., 06:07
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #5993 · 02.03.2026 г., 06:06
Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #5961 · 23.02.2026 г., 06:56
☁️ Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI
@AiArtsGalleryAnime · Post #5913 · 11.02.2026 г., 06:43
☁️ Serene AI Moments ☁️ Calm and beautiful anime art created with artificial intelligence. #AnimeAesthetic#Serene#AiArt#CalmAnime#DigitalPainting#AI