Python: how to enclose strings in a list using <and>

I would like to enclose the lines inside a list in <> (formatted as <% s>). The current code does the following:

def create_worker (general_logger, general_config):
    arguments = ["worker_name", "worker_module", "worker_class"]
    __check_arguments(arguments)

def __check_arguments(arguments):
    if len(sys.argv) < 2 + len(arguments):
        print "Usage: %s delete-project %s" % (__file__," ".join(arguments))
        sys.exit(10)

      

The current output looks like this:

Usage: ...\handler_scripts.py delete-project worker_name worker_module worker_class

      

and should look like this:

Usage: ...\handler_scripts.py delete-project <worker_name> <worker_module> <worker_class>

      

Is there a short way to do this?

Hi Michael

+2


source share


4 answers


What about:



print "Usage: %s delete-project %s" % (__file__," ".join('<%s>'% arg for arg in arguments))

      

+5


source


Use a list comprehension: ['<%s>' % s for s in arguments]

.



0


source


Replace the bit join

like this:

' '.join('<%s>' % s for s in arguments)

      

0


source


Replace

(__file__," ".join(arguments))

      

from

(__file__," ".join("<%s>" % a for a in arguments))

      

0


source







All Articles