removing nested iffs

Josh Benner sjbenner at
Fri Jul 29 15:40:52 EDT 2011

I'm writing a function to create a string that gets longer iff an argument
is defined.  In there a more elegant way than nesting all those ifs?

def format_rsync_src_string(args, server="RSYNC"):
    """ Format an rsync source directory string. """
    if args.server is None:
        raise CopyNightlyError("No rsync server provided.")
    src = "{0}::".format(args.server)
    if args.project not None:
        src += "{0}/".format(args.project)
        if args.version not None:
                src += "{0}/".format(args.version)
                if not None:
                    src += "Build {0}".format(
    return src
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list