I believe I've got it now. With a trick from the FAQ. if hasattr(self, scommand): parameter_s = " %s " % parameter_s # Protect quotes at the end return shell+scommand+'(parameter_s=r"""%s"""[1:-1])' % parameter_s else: return shell+line+'()' You put extra spaces on, then pull them off with the slice after quoting is complete. gb