Q:

Are there any equivalent for groovy """ in python?

I'm very new to python. I'm from groovy and I use """" to write some text into files the way I wish. 
Are there any equivalent way in python to?
Note that I want to create a file that has more than 20 lines. So I need some easy and elegant way.
Thanks in advance.

A:

It's not clear what exactly you're asking about.
The ability to use ''' or """ for multi-line strings in Groovy was borrowed directly from Python, so of course you can do the exact same thing in Python.
However, the ability to use " or """ for interpolated strings in Groovy was borrowed from sh, and Python does not have the same feature. In Python, ' and " strings are identical, and neither does interpolation.
The idiomatic Python alternative is format. This is a method on the str and unicode classes, which you use like this:
s = """This is a string with a {variable} to fill in.
Here's a {second} one
""".format(variable="field", second="'nother")

If you write that to a file, you'll get this:
This is a string with a field to fill in.
Here's a 'nother one

There are plenty of variations. If you want to pass arguments by position instead of name, you can use {0} instead of {variable}—or, for simple cases where they're inserted in order, just use {} (but be careful with i18n). You can also put formatting information in, e.g., to print the repr (sort of "what you would type to get this value") instead of the str (a human-readable representation). Read the docs linked above for details.
Python also has an older mechanism, which is being gradually phased out, that uses the % operator and a format spec based on, but pretty different from, C-style printf. For example:
s = """This is a string with a %(variable)s to fill in.
Here's a %(second)s one
""" % {"variable": "field", "second": "'nother"}

Again, there are plenty of variations available; again, read the docs linked above for details. But really, you only want to use this if you're dealing with a lot of old code, or translating from printf or Windows-style or similar formats, or need to run on Python 2.5 or earlier.
If none of this is sufficient for you, there are 69,105 modules on PyPI (and recipes on ActiveState, etc.) for doing everything from as-close-to-perl-as-possible interpolation to templating HTML pages.

