Specify string with uniform indentation ignored

T

tobiah

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
 
S

sjdevnull

tobiah said:
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.
 
S

Sam Pointon

tobiah said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top