I have the following python code:
def split_arg(argv):
buildDescriptor = argv[1]
buildfile, target = buildDescriptor.split("#")
return buildfile, target
It expects a string (argv[1]
) of the form buildfile#target
and splits them into two variables of the same name. So a string like "my-buildfile#some-target" will get broken into my-buildfile and some-target respectively.
Sometimes though, there won't be "#" and target; sometimes you'll just have "my-buildfile", in which case I just want target to be "" (empty).
How do I modify this function so that it will handle instances where "#" doesn't exist and it returns buildfile with an empty target?
Currently, if I pass just the buildfile, it throws an error:
buildfile, target = buildDescriptor.split("#")
ValueError: need more than 1 value to unpack
Thanks in advance!