Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:48:55+00:00 2026-06-12T19:48:55+00:00

I have the following python code: def split_arg(argv): buildDescriptor = argv[1] buildfile, target =

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:48:56+00:00Added an answer on June 12, 2026 at 7:48 pm

    First, put the result of the split in a list:

    split_build_descriptor = buildDescriptor.split("#")
    

    Then check how many elements it has:

    if len(split_build_descriptor) == 1:
        buildfile = split_build_descriptor[0]
        target = ''
    elif len(split_build_descriptor) == 2:
        buildfile, target = split_build_descriptor
    else:
        pass  # handle error; there's two #s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following python code: def outer(): string = def inner(): string
I have the following python code using the twisted API. def function(self,filename): def results(result):
I have the following chunk of python code: import hashlib class User: def _set_password(self,
I have the following python code: class FooMeta(type): def __setattr__(self, name, value): print name,
I have the following python code. class MainPage(BaseHandler): def post(self, location_id): reservations = self.request.get_all('reservations')
I have the following python code that expects data coming from the serial port,
Kinda knew to Python: I have the following code: def printCSV(output, values, header): 63
I have the following Python code: def find_words(letters): results = set() def extend_prefix(w, letters):
Look at the following Python code: def function(x): return x, x+1 sequence = range(5)
I have the following situation in my python code: class Parent(object): def run(self): print

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.