Değişkenleri, tek bir dizeye önceden tanımlanmış bir ayırıcıyla birleştirmenin temiz bir yolunu arıyorum. Sorun şu ki, bazen bu değişkenlerin bazıları her zaman mevcut değildir veya Yok olarak ayarlanabilir. Ayırıcı dizgisini de kopyalayamıyorum. Sorunun Örnek:Birleştirilebilen İçeren Dizeleri ve (YokType/Tanımsız) birleştirme dizesi
# This works because I have all strings
str('-').join(('productX', 'deployment-package', '1.2.3.4'))
# 'productX-deployment-package-1.2.3.4'
# But I have more args that might be None/or not exist like and that breaks
str('-').join(('productX', 'deployment-package', '1.2.3.4', idontexist, alsonotexist))
str('-').join(('productX', 'deployment-package', '1.2.3.4', None, None, None))
# If I set the other missing variables to empty strings, I get duplicated joiners
str('-').join(('productX', 'deployment-package', '1.2.3.4', '', '', ''))
# 'productX-deployment-package-1.2.3.4---'
Bunu yapmak için güzel temiz bir yolu var mı?
'kullanmak '-' ('-') yerine str' arasında join' ben kendi cevap bu tercih – jamylak