Specify string with uniform indentation ignored

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tobiah

    Specify string with uniform indentation ignored

    Like a docstring, I would like to specify a string such as:

    def thing:

    string = """
    function otherlang(){
    doit()
    }
    """

    And have the string end up actually being defined as:

    """
    function otherlang(){
    doit()
    }
    """

    Is there a built in way to do this? I don't much
    care for:

    string = "function otherlang(){"
    string += " doit()"
    string += "}"

    Thanks,

    Tobiah

    --
    Posted via a free Usenet account from http://www.teranews.com

  • sjdevnull@yahoo.com

    #2
    Re: Specify string with uniform indentation ignored

    tobiah wrote:
    Is there a built in way to do this? I don't much
    care for:
    >
    string = "function otherlang(){"
    string += " doit()"
    string += "}"
    That can be somewhat simplified to:
    string = "function otherlang(){"\
    " doit()"\
    "}"
    It's not exactly what you wanted, I know.

    Comment

    • Sam Pointon

      #3
      Re: Specify string with uniform indentation ignored

      tobiah wrote:
      Like a docstring, I would like to specify a string such as:
      >
      def thing:
      >
      string = """
      function otherlang(){
      doit()
      }
      """
      >
      And have the string end up actually being defined as:
      >
      """
      function otherlang(){
      doit()
      }
      """
      >
      Is there a built in way to do this? I don't much
      care for:
      >
      string = "function otherlang(){"
      string += " doit()"
      string += "}"
      textwrap.dedent ought to do exactly what you want.

      --Sam

      Comment

      • tobiah

        #4
        Re: Specify string with uniform indentation ignored

        That would be it. Thanks.
        >Is there a built in way to do this? I don't much
        >care for:
        >>
        > string = "function otherlang(){"
        > string += " doit()"
        > string += "}"
        >
        textwrap.dedent ought to do exactly what you want.
        >
        --Sam
        >
        --
        Posted via a free Usenet account from http://www.teranews.com

        Comment

        Working...