python - Conditionally parsing a string -
i'm working on small script compile csv file.
i've come code combine string.
site = "{}.{}".format(subdomain, fulldomain)
however there situation subdomain may not exist. if case, output ".domain.tld" not correct.
i wondering if there condition can add in format instruction above, or simpler check output , remove dot @ beginning if any.
thanks
how pretty straightforward one-liner?
"{}{}{}".format(subdomain, '.' if subdomain else '', fulldomain)
and can name each format item like:
"{subdomain}{dot}{fulldomain}".format(subdomain=subdomain, dot='.' if subdomain else '', fulldomain=fulldomain)
or, can go way:
"{}{}".format(subdomain + '.' if subdomain else '', fulldomain)